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
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
16 changes: 11 additions & 5 deletions engine/commands/model_alias_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ void ModelAliasCmd::Exec(const std::string& model_handle,
const std::string& model_alias) {
cortex::db::Models modellist_handler;
try {
if (modellist_handler.UpdateModelAlias(model_handle, model_alias)) {
CLI_LOG("Successfully set model alias '" + model_alias +
"' for modeID '" + model_handle + "'.");
auto result = modellist_handler.UpdateModelAlias(model_handle, model_alias);
if (result.has_error()) {
CLI_LOG(result.error());
} else {
CLI_LOG("Unable to set model alias for modelID '" + model_handle +
"': model alias '" + model_alias + "' is not unique!");
if (result.value()) {
CLI_LOG("Successfully set model alias '" + model_alias +
"' for modeID '" + model_handle + "'.");
} else {
CLI_LOG("Unable to set model alias for modelID '" + model_handle +
"': model alias '" + model_alias + "' is not unique!");
}
}

} catch (const std::exception& e) {
CLI_LOG("Error when setting model alias ('" + model_alias +
"') for modelID '" + model_handle + "':" + e.what());
Expand Down
67 changes: 43 additions & 24 deletions engine/controllers/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ void Models::GetModel(
config::YamlHandler yaml_handler;
auto model_entry = modellist_handler.GetModelInfo(model_handle);
if (model_entry.has_error()) {
CLI_LOG("Error: " + model_entry.error());
// CLI_LOG("Error: " + model_entry.error());
ret["data"] = data;
ret["result"] = "Fail to get model information";
ret["message"] = "Error: " + model_entry.error();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k400BadRequest);
callback(resp);
return;
}
yaml_handler.ModelConfigFromFile(model_entry.value().path_to_model_yaml);
Expand Down Expand Up @@ -234,7 +240,7 @@ void Models::ImportModel(
gguf_handler.Parse(modelPath);
config::ModelConfig model_config = gguf_handler.GetModelConfig();
model_config.files.push_back(modelPath);
model_config.name = modelHandle;
model_config.model = modelHandle;
yaml_handler.UpdateModelConfig(model_config);

if (modellist_utils_obj.AddModelEntry(model_entry).value()) {
Expand Down Expand Up @@ -293,29 +299,42 @@ void Models::SetModelAlias(

cortex::db::Models modellist_handler;
try {
if (modellist_handler.UpdateModelAlias(model_handle, model_alias)) {
std::string message = "Successfully set model alias '" + model_alias +
"' for modeID '" + model_handle + "'.";
LOG_INFO << message;
Json::Value ret;
ret["result"] = "OK";
ret["modelHandle"] = model_handle;
ret["message"] = message;
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k200OK);
callback(resp);
} else {
std::string message = "Unable to set model alias for modelID '" +
model_handle + "': model alias '" + model_alias +
"' is not unique!";
auto result = modellist_handler.UpdateModelAlias(model_handle, model_alias);
if (result.has_error()) {
std::string message = result.error();
LOG_ERROR << message;
Json::Value ret;
ret["result"] = "Set alias failed!";
ret["modelHandle"] = model_handle;
ret["message"] = message;
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k400BadRequest);
callback(resp);
Json::Value ret;
ret["result"] = "Set alias failed!";
ret["modelHandle"] = model_handle;
ret["message"] = message;
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k400BadRequest);
callback(resp);
} else {
if (result.value()) {
std::string message = "Successfully set model alias '" + model_alias +
"' for modeID '" + model_handle + "'.";
LOG_INFO << message;
Json::Value ret;
ret["result"] = "OK";
ret["modelHandle"] = model_handle;
ret["message"] = message;
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k200OK);
callback(resp);
} else {
std::string message = "Unable to set model alias for modelID '" +
model_handle + "': model alias '" + model_alias +
"' is not unique!";
LOG_ERROR << message;
Json::Value ret;
ret["result"] = "Set alias failed!";
ret["modelHandle"] = model_handle;
ret["message"] = message;
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k400BadRequest);
callback(resp);
}
}
} catch (const std::exception& e) {
std::string message = "Error when setting model alias ('" + model_alias +
Expand Down
2 changes: 1 addition & 1 deletion engine/controllers/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Models : public drogon::HttpController<Models> {
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::UpdateModel, "/update", Post);
METHOD_ADD(Models::ImportModel, "/import", Post);
METHOD_ADD(Models::DeleteModel, "/{1}", Delete);
METHOD_ADD(Models::SetModelAlias, "/alias", Post);
Expand Down
Loading
Loading