Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 0 additions & 55 deletions engine/commands/cmd_info.cc

This file was deleted.

14 changes: 0 additions & 14 deletions engine/commands/cmd_info.h

This file was deleted.

1 change: 0 additions & 1 deletion engine/commands/model_get_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iomanip>
#include <iostream>
#include <vector>
#include "cmd_info.h"
#include "config/yaml_config.h"
#include "database/models.h"
#include "utils/file_manager_utils.h"
Expand Down
2 changes: 1 addition & 1 deletion engine/commands/model_list_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void ModelListCmd::Exec() {
count += 1;
yaml_handler.ModelConfigFromFile(model_entry.path_to_model_yaml);
auto model_config = yaml_handler.GetModelConfig();
table.add_row({std::to_string(count), model_entry.model_id,
table.add_row({std::to_string(count), model_entry.model,
model_entry.model_alias, model_config.engine,
model_config.version});
yaml_handler.Reset();
Expand Down
1 change: 0 additions & 1 deletion engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "command_line_parser.h"
#include "commands/chat_cmd.h"
#include "commands/chat_completion_cmd.h"
#include "commands/cmd_info.h"
#include "commands/cortex_upd_cmd.h"
#include "commands/engine_get_cmd.h"
#include "commands/engine_install_cmd.h"
Expand Down
2 changes: 1 addition & 1 deletion engine/controllers/engines.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Engines : public drogon::HttpController<Engines> {
Engines() : engine_service_{EngineService()} {};

METHOD_LIST_BEGIN
METHOD_ADD(Engines::InstallEngine, "/{1}/install", Post);
METHOD_ADD(Engines::InstallEngine, "/install/{1}", Post);
METHOD_ADD(Engines::UninstallEngine, "/{1}", Delete);
METHOD_ADD(Engines::ListEngine, "", Get);
METHOD_ADD(Engines::GetEngine, "/{1}", Get);
Expand Down
42 changes: 17 additions & 25 deletions engine/controllers/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

void Models::PullModel(const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) {
if (!http_util::HasFieldInReq(req, callback, "modelId")) {
if (!http_util::HasFieldInReq(req, callback, "model")) {
return;
}

auto model_handle = (*(req->getJsonObject())).get("modelId", "").asString();
auto model_handle = (*(req->getJsonObject())).get("model", "").asString();
if (model_handle.empty()) {
Json::Value ret;
ret["result"] = "Bad Request";
Expand Down Expand Up @@ -103,22 +103,18 @@ void Models::ListModel(
}
}

void Models::GetModel(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const {
if (!http_util::HasFieldInReq(req, callback, "modelId")) {
return;
}
auto model_handle = (*(req->getJsonObject())).get("modelId", "").asString();
LOG_DEBUG << "GetModel, Model handle: " << model_handle;
void Models::GetModel(const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback,
const std::string& model_id) const {
LOG_DEBUG << "GetModel, Model handle: " << model_id;
Json::Value ret;
ret["object"] = "list";
Json::Value data(Json::arrayValue);

try {
cortex::db::Models modellist_handler;
config::YamlHandler yaml_handler;
auto model_entry = modellist_handler.GetModelInfo(model_handle);
auto model_entry = modellist_handler.GetModelInfo(model_id);
if (model_entry.has_error()) {
// CLI_LOG("Error: " + model_entry.error());
ret["data"] = data;
Expand All @@ -142,7 +138,7 @@ void Models::GetModel(
callback(resp);
} catch (const std::exception& e) {
std::string message = "Fail to get model information with ID '" +
model_handle + "': " + e.what();
model_id + "': " + e.what();
LOG_ERROR << message;
ret["data"] = data;
ret["result"] = "Fail to get model information";
Expand Down Expand Up @@ -172,13 +168,9 @@ void Models::DeleteModel(const HttpRequestPtr& req,
}
}

void Models::UpdateModel(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const {
if (!http_util::HasFieldInReq(req, callback, "modelId")) {
return;
}
auto model_id = (*(req->getJsonObject())).get("modelId", "").asString();
void Models::UpdateModel(const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback,
const std::string& model_id) const {
auto json_body = *(req->getJsonObject());
try {
cortex::db::Models model_list_utils;
Expand All @@ -198,7 +190,7 @@ void Models::UpdateModel(
ret["message"] = message;

auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k400BadRequest);
resp->setStatusCode(k200OK);
callback(resp);

} catch (const std::exception& e) {
Expand All @@ -218,11 +210,11 @@ void Models::UpdateModel(
void Models::ImportModel(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const {
if (!http_util::HasFieldInReq(req, callback, "modelId") ||
if (!http_util::HasFieldInReq(req, callback, "model") ||
!http_util::HasFieldInReq(req, callback, "modelPath")) {
return;
}
auto modelHandle = (*(req->getJsonObject())).get("modelId", "").asString();
auto modelHandle = (*(req->getJsonObject())).get("model", "").asString();
auto modelPath = (*(req->getJsonObject())).get("modelPath", "").asString();
config::GGUFHandler gguf_handler;
config::YamlHandler yaml_handler;
Expand Down Expand Up @@ -288,11 +280,11 @@ void Models::ImportModel(
void Models::SetModelAlias(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const {
if (!http_util::HasFieldInReq(req, callback, "modelId") ||
if (!http_util::HasFieldInReq(req, callback, "model") ||
!http_util::HasFieldInReq(req, callback, "modelAlias")) {
return;
}
auto model_handle = (*(req->getJsonObject())).get("modelId", "").asString();
auto model_handle = (*(req->getJsonObject())).get("model", "").asString();
auto model_alias = (*(req->getJsonObject())).get("modelAlias", "").asString();
LOG_DEBUG << "GetModel, Model handle: " << model_handle
<< ", Model alias: " << model_alias;
Expand Down Expand Up @@ -390,7 +382,7 @@ void Models::StopModel(const HttpRequestPtr& req,
callback(resp);
} else {
Json::Value ret;
ret["message"] = "Started successfully!";
ret["message"] = "Stopped successfully!";
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k200OK);
callback(resp);
Expand Down
13 changes: 7 additions & 6 deletions engine/controllers/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Models : public drogon::HttpController<Models> {
METHOD_LIST_BEGIN
METHOD_ADD(Models::PullModel, "/pull", Post);
METHOD_ADD(Models::ListModel, "", Get);
METHOD_ADD(Models::GetModel, "/get", Post);
METHOD_ADD(Models::UpdateModel, "/update", Post);
METHOD_ADD(Models::GetModel, "/{1}", Get);
METHOD_ADD(Models::UpdateModel, "/{1}", Post);
METHOD_ADD(Models::ImportModel, "/import", Post);
METHOD_ADD(Models::DeleteModel, "/{1}", Delete);
METHOD_ADD(Models::SetModelAlias, "/alias", Post);
Expand All @@ -27,10 +27,11 @@ class Models : public drogon::HttpController<Models> {
void ListModel(const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const;
void GetModel(const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const;
void UpdateModel(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const;
std::function<void(const HttpResponsePtr&)>&& callback,
const std::string& model_id) const;
void UpdateModel(const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback,
const std::string& model_id) const;
void ImportModel(
const HttpRequestPtr& req,
std::function<void(const HttpResponsePtr&)>&& callback) const;
Expand Down
Loading
Loading