Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 680c011

Browse files
authored
chore: add /v1/models/ APIs (#1443)
* chore: add /v1/models/ APIs * fix: remove id * fix: id
1 parent 7dad5a1 commit 680c011

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

engine/config/model_config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ struct ModelConfig {
170170
Json::Value ToJson() const {
171171
Json::Value obj;
172172

173-
obj["id"] = id;
174173
obj["name"] = name;
175174
obj["model"] = model;
176175
obj["version"] = version;

engine/controllers/models.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void Models::ListModel(
8181
.string());
8282
auto model_config = yaml_handler.GetModelConfig();
8383
Json::Value obj = model_config.ToJson();
84-
84+
obj["id"] = model_config.model;
8585
data.append(std::move(obj));
8686
yaml_handler.Reset();
8787
} catch (const std::exception& e) {
@@ -114,16 +114,15 @@ void Models::GetModel(const HttpRequestPtr& req,
114114
namespace fmu = file_manager_utils;
115115
LOG_DEBUG << "GetModel, Model handle: " << model_id;
116116
Json::Value ret;
117-
ret["object"] = "list";
118-
Json::Value data(Json::arrayValue);
119117

120118
try {
121119
cortex::db::Models modellist_handler;
122120
config::YamlHandler yaml_handler;
123121
auto model_entry = modellist_handler.GetModelInfo(model_id);
124122
if (model_entry.has_error()) {
125123
// CLI_LOG("Error: " + model_entry.error());
126-
ret["data"] = data;
124+
ret["id"] = model_id;
125+
ret["object"] = "model";
127126
ret["result"] = "Fail to get model information";
128127
ret["message"] = "Error: " + model_entry.error();
129128
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
@@ -137,10 +136,10 @@ void Models::GetModel(const HttpRequestPtr& req,
137136
.string());
138137
auto model_config = yaml_handler.GetModelConfig();
139138

140-
Json::Value obj = model_config.ToJson();
139+
ret = model_config.ToJson();
141140

142-
data.append(std::move(obj));
143-
ret["data"] = data;
141+
ret["id"] = model_config.model;
142+
ret["object"] = "model";
144143
ret["result"] = "OK";
145144
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
146145
resp->setStatusCode(k200OK);
@@ -149,7 +148,8 @@ void Models::GetModel(const HttpRequestPtr& req,
149148
std::string message =
150149
"Fail to get model information with ID '" + model_id + "': " + e.what();
151150
LOG_ERROR << message;
152-
ret["data"] = data;
151+
ret["id"] = model_id;
152+
ret["object"] = "model";
153153
ret["result"] = "Fail to get model information";
154154
ret["message"] = message;
155155
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);

engine/controllers/models.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ class Models : public drogon::HttpController<Models> {
2020
METHOD_ADD(Models::SetModelAlias, "/alias", Post);
2121
METHOD_ADD(Models::StartModel, "/start", Post);
2222
METHOD_ADD(Models::StopModel, "/stop", Post);
23+
24+
ADD_METHOD_TO(Models::PullModel, "/v1/models/pull", Post);
25+
ADD_METHOD_TO(Models::ListModel, "/v1/models", Get);
26+
ADD_METHOD_TO(Models::GetModel, "/v1/models/{1}", Get);
27+
ADD_METHOD_TO(Models::UpdateModel, "/v1/models/{1}", Post);
28+
ADD_METHOD_TO(Models::ImportModel, "/v1/models/import", Post);
29+
ADD_METHOD_TO(Models::DeleteModel, "/v1/models/{1}", Delete);
30+
ADD_METHOD_TO(Models::SetModelAlias, "/v1/models/alias", Post);
31+
ADD_METHOD_TO(Models::StartModel, "/v1/models/start", Post);
32+
ADD_METHOD_TO(Models::StopModel, "/v1/models/stop", Post);
2333
METHOD_LIST_END
2434

2535
void PullModel(const HttpRequestPtr& req,

engine/controllers/server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class server : public drogon::HttpController<server>,
5656

5757
// Openai compatible path
5858
ADD_METHOD_TO(server::ChatCompletion, "/v1/chat/completions", Post);
59-
ADD_METHOD_TO(server::GetModels, "/v1/models", Get);
59+
// ADD_METHOD_TO(server::GetModels, "/v1/models", Get);
6060
ADD_METHOD_TO(server::FineTuning, "/v1/fine_tuning/job", Post);
6161

6262
// ADD_METHOD_TO(server::handlePrelight, "/v1/chat/completions", Options);

engine/controllers/swagger.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ Json::Value SwaggerController::generateOpenAPISpec() {
169169
// Models Endpoints
170170
{
171171
// PullModel
172-
Json::Value& pull = spec["paths"]["/models/pull"]["post"];
172+
Json::Value& pull = spec["paths"]["/v1/models/pull"]["post"];
173173
pull["summary"] = "Pull a model";
174174
pull["requestBody"]["content"]["application/json"]["schema"]["type"] =
175175
"object";
@@ -183,15 +183,15 @@ Json::Value SwaggerController::generateOpenAPISpec() {
183183
pull["responses"]["400"]["description"] = "Bad request";
184184

185185
// ListModel
186-
Json::Value& list = spec["paths"]["/models"]["get"];
186+
Json::Value& list = spec["paths"]["/v1/models"]["get"];
187187
list["summary"] = "List all models";
188188
list["responses"]["200"]["description"] =
189189
"List of models retrieved successfully";
190190
list["responses"]["400"]["description"] =
191191
"Failed to get list model information";
192192

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

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

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

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

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

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

460460
// Stop Model
461-
Json::Value& stop = spec["paths"]["/models/stop"]["post"];
461+
Json::Value& stop = spec["paths"]["/v1/models/stop"]["post"];
462462
stop["summary"] = "Stop model";
463463
stop["requestBody"]["content"]["application/json"]["schema"]["type"] =
464464
"object";

0 commit comments

Comments
 (0)