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
1 change: 0 additions & 1 deletion engine/config/model_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ struct ModelConfig {
Json::Value ToJson() const {
Json::Value obj;

obj["id"] = id;
obj["name"] = name;
obj["model"] = model;
obj["version"] = version;
Expand Down
16 changes: 8 additions & 8 deletions engine/controllers/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void Models::ListModel(
.string());
auto model_config = yaml_handler.GetModelConfig();
Json::Value obj = model_config.ToJson();

obj["id"] = model_config.model;
data.append(std::move(obj));
yaml_handler.Reset();
} catch (const std::exception& e) {
Expand Down Expand Up @@ -114,16 +114,15 @@ void Models::GetModel(const HttpRequestPtr& req,
namespace fmu = file_manager_utils;
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_id);
if (model_entry.has_error()) {
// CLI_LOG("Error: " + model_entry.error());
ret["data"] = data;
ret["id"] = model_id;
ret["object"] = "model";
ret["result"] = "Fail to get model information";
ret["message"] = "Error: " + model_entry.error();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
Expand All @@ -137,10 +136,10 @@ void Models::GetModel(const HttpRequestPtr& req,
.string());
auto model_config = yaml_handler.GetModelConfig();

Json::Value obj = model_config.ToJson();
ret = model_config.ToJson();

data.append(std::move(obj));
ret["data"] = data;
ret["id"] = model_config.model;
ret["object"] = "model";
ret["result"] = "OK";
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k200OK);
Expand All @@ -149,7 +148,8 @@ void Models::GetModel(const HttpRequestPtr& req,
std::string message =
"Fail to get model information with ID '" + model_id + "': " + e.what();
LOG_ERROR << message;
ret["data"] = data;
ret["id"] = model_id;
ret["object"] = "model";
ret["result"] = "Fail to get model information";
ret["message"] = message;
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
Expand Down
10 changes: 10 additions & 0 deletions engine/controllers/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class Models : public drogon::HttpController<Models> {
METHOD_ADD(Models::SetModelAlias, "/alias", Post);
METHOD_ADD(Models::StartModel, "/start", Post);
METHOD_ADD(Models::StopModel, "/stop", Post);

ADD_METHOD_TO(Models::PullModel, "/v1/models/pull", Post);
ADD_METHOD_TO(Models::ListModel, "/v1/models", Get);
ADD_METHOD_TO(Models::GetModel, "/v1/models/{1}", Get);
ADD_METHOD_TO(Models::UpdateModel, "/v1/models/{1}", Post);
ADD_METHOD_TO(Models::ImportModel, "/v1/models/import", Post);
ADD_METHOD_TO(Models::DeleteModel, "/v1/models/{1}", Delete);
ADD_METHOD_TO(Models::SetModelAlias, "/v1/models/alias", Post);
ADD_METHOD_TO(Models::StartModel, "/v1/models/start", Post);
ADD_METHOD_TO(Models::StopModel, "/v1/models/stop", Post);
METHOD_LIST_END

void PullModel(const HttpRequestPtr& req,
Expand Down
2 changes: 1 addition & 1 deletion engine/controllers/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class server : public drogon::HttpController<server>,

// Openai compatible path
ADD_METHOD_TO(server::ChatCompletion, "/v1/chat/completions", Post);
ADD_METHOD_TO(server::GetModels, "/v1/models", Get);
// ADD_METHOD_TO(server::GetModels, "/v1/models", Get);
ADD_METHOD_TO(server::FineTuning, "/v1/fine_tuning/job", Post);

// ADD_METHOD_TO(server::handlePrelight, "/v1/chat/completions", Options);
Expand Down
18 changes: 9 additions & 9 deletions engine/controllers/swagger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
// Models Endpoints
{
// PullModel
Json::Value& pull = spec["paths"]["/models/pull"]["post"];
Json::Value& pull = spec["paths"]["/v1/models/pull"]["post"];
pull["summary"] = "Pull a model";
pull["requestBody"]["content"]["application/json"]["schema"]["type"] =
"object";
Expand All @@ -183,15 +183,15 @@ Json::Value SwaggerController::generateOpenAPISpec() {
pull["responses"]["400"]["description"] = "Bad request";

// ListModel
Json::Value& list = spec["paths"]["/models"]["get"];
Json::Value& list = spec["paths"]["/v1/models"]["get"];
list["summary"] = "List all models";
list["responses"]["200"]["description"] =
"List of models retrieved successfully";
list["responses"]["400"]["description"] =
"Failed to get list model information";

// GetModel
Json::Value& get = spec["paths"]["/models/{model}"]["get"];
Json::Value& get = spec["paths"]["/v1/models/{model}"]["get"];
get["summary"] = "Get model details";
get["parameters"][0]["name"] = "model";
get["parameters"][0]["in"] = "path";
Expand All @@ -211,7 +211,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
["message"]["type"] = "string";

// UpdateModel Endpoint
Json::Value& update = spec["paths"]["/models/{model}"]["post"];
Json::Value& update = spec["paths"]["/v1/models/{model}"]["post"];
update["summary"] = "Update model details";
update["description"] =
"Update various attributes of a model based on the ModelConfig "
Expand Down Expand Up @@ -398,7 +398,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
"Detailed error message";

// ImportModel
Json::Value& import = spec["paths"]["/models/import"]["post"];
Json::Value& import = spec["paths"]["/v1/models/import"]["post"];
import["summary"] = "Import a model";
import["requestBody"]["content"]["application/json"]["schema"]["type"] =
"object";
Expand All @@ -416,7 +416,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
import["responses"]["400"]["description"] = "Failed to import model";

// DeleteModel
Json::Value& del = spec["paths"]["/models/{model}"]["delete"];
Json::Value& del = spec["paths"]["/v1/models/{model}"]["delete"];
del["summary"] = "Delete a model";
del["parameters"][0]["name"] = "model";
del["parameters"][0]["in"] = "path";
Expand All @@ -426,7 +426,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
del["responses"]["400"]["description"] = "Failed to delete model";

// SetModelAlias
Json::Value& alias = spec["paths"]["/models/alias"]["post"];
Json::Value& alias = spec["paths"]["/v1/models/alias"]["post"];
alias["summary"] = "Set model alias";
alias["requestBody"]["content"]["application/json"]["schema"]["type"] =
"object";
Expand All @@ -444,7 +444,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
alias["responses"]["400"]["description"] = "Failed to set model alias";

// Start Model
Json::Value& start = spec["paths"]["/models/start"]["post"];
Json::Value& start = spec["paths"]["/v1/models/start"]["post"];
start["summary"] = "Start model";
start["requestBody"]["content"]["application/json"]["schema"]["type"] =
"object";
Expand All @@ -458,7 +458,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
start["responses"]["400"]["description"] = "Failed to start model";

// Stop Model
Json::Value& stop = spec["paths"]["/models/stop"]["post"];
Json::Value& stop = spec["paths"]["/v1/models/stop"]["post"];
stop["summary"] = "Stop model";
stop["requestBody"]["content"]["application/json"]["schema"]["type"] =
"object";
Expand Down
Loading