1212
1313void Models::PullModel (const HttpRequestPtr& req,
1414 std::function<void (const HttpResponsePtr&)>&& callback) {
15- if (!http_util::HasFieldInReq (req, callback, " modelId " )) {
15+ if (!http_util::HasFieldInReq (req, callback, " model " )) {
1616 return ;
1717 }
1818
19- auto model_handle = (*(req->getJsonObject ())).get (" modelId " , " " ).asString ();
19+ auto model_handle = (*(req->getJsonObject ())).get (" model " , " " ).asString ();
2020 if (model_handle.empty ()) {
2121 Json::Value ret;
2222 ret[" result" ] = " Bad Request" ;
@@ -103,22 +103,18 @@ void Models::ListModel(
103103 }
104104}
105105
106- void Models::GetModel (
107- const HttpRequestPtr& req,
108- std::function<void (const HttpResponsePtr&)>&& callback) const {
109- if (!http_util::HasFieldInReq (req, callback, " modelId" )) {
110- return ;
111- }
112- auto model_handle = (*(req->getJsonObject ())).get (" modelId" , " " ).asString ();
113- LOG_DEBUG << " GetModel, Model handle: " << model_handle;
106+ void Models::GetModel (const HttpRequestPtr& req,
107+ std::function<void (const HttpResponsePtr&)>&& callback,
108+ const std::string& model_id) const {
109+ LOG_DEBUG << " GetModel, Model handle: " << model_id;
114110 Json::Value ret;
115111 ret[" object" ] = " list" ;
116112 Json::Value data (Json::arrayValue);
117113
118114 try {
119115 cortex::db::Models modellist_handler;
120116 config::YamlHandler yaml_handler;
121- auto model_entry = modellist_handler.GetModelInfo (model_handle );
117+ auto model_entry = modellist_handler.GetModelInfo (model_id );
122118 if (model_entry.has_error ()) {
123119 // CLI_LOG("Error: " + model_entry.error());
124120 ret[" data" ] = data;
@@ -142,7 +138,7 @@ void Models::GetModel(
142138 callback (resp);
143139 } catch (const std::exception& e) {
144140 std::string message = " Fail to get model information with ID '" +
145- model_handle + " ': " + e.what ();
141+ model_id + " ': " + e.what ();
146142 LOG_ERROR << message;
147143 ret[" data" ] = data;
148144 ret[" result" ] = " Fail to get model information" ;
@@ -172,13 +168,9 @@ void Models::DeleteModel(const HttpRequestPtr& req,
172168 }
173169}
174170
175- void Models::UpdateModel (
176- const HttpRequestPtr& req,
177- std::function<void (const HttpResponsePtr&)>&& callback) const {
178- if (!http_util::HasFieldInReq (req, callback, " modelId" )) {
179- return ;
180- }
181- auto model_id = (*(req->getJsonObject ())).get (" modelId" , " " ).asString ();
171+ void Models::UpdateModel (const HttpRequestPtr& req,
172+ std::function<void (const HttpResponsePtr&)>&& callback,
173+ const std::string& model_id) const {
182174 auto json_body = *(req->getJsonObject ());
183175 try {
184176 cortex::db::Models model_list_utils;
@@ -198,7 +190,7 @@ void Models::UpdateModel(
198190 ret[" message" ] = message;
199191
200192 auto resp = cortex_utils::CreateCortexHttpJsonResponse (ret);
201- resp->setStatusCode (k400BadRequest );
193+ resp->setStatusCode (k200OK );
202194 callback (resp);
203195
204196 } catch (const std::exception& e) {
@@ -218,11 +210,11 @@ void Models::UpdateModel(
218210void Models::ImportModel (
219211 const HttpRequestPtr& req,
220212 std::function<void (const HttpResponsePtr&)>&& callback) const {
221- if (!http_util::HasFieldInReq (req, callback, " modelId " ) ||
213+ if (!http_util::HasFieldInReq (req, callback, " model " ) ||
222214 !http_util::HasFieldInReq (req, callback, " modelPath" )) {
223215 return ;
224216 }
225- auto modelHandle = (*(req->getJsonObject ())).get (" modelId " , " " ).asString ();
217+ auto modelHandle = (*(req->getJsonObject ())).get (" model " , " " ).asString ();
226218 auto modelPath = (*(req->getJsonObject ())).get (" modelPath" , " " ).asString ();
227219 config::GGUFHandler gguf_handler;
228220 config::YamlHandler yaml_handler;
@@ -288,11 +280,11 @@ void Models::ImportModel(
288280void Models::SetModelAlias (
289281 const HttpRequestPtr& req,
290282 std::function<void (const HttpResponsePtr&)>&& callback) const {
291- if (!http_util::HasFieldInReq (req, callback, " modelId " ) ||
283+ if (!http_util::HasFieldInReq (req, callback, " model " ) ||
292284 !http_util::HasFieldInReq (req, callback, " modelAlias" )) {
293285 return ;
294286 }
295- auto model_handle = (*(req->getJsonObject ())).get (" modelId " , " " ).asString ();
287+ auto model_handle = (*(req->getJsonObject ())).get (" model " , " " ).asString ();
296288 auto model_alias = (*(req->getJsonObject ())).get (" modelAlias" , " " ).asString ();
297289 LOG_DEBUG << " GetModel, Model handle: " << model_handle
298290 << " , Model alias: " << model_alias;
@@ -390,7 +382,7 @@ void Models::StopModel(const HttpRequestPtr& req,
390382 callback (resp);
391383 } else {
392384 Json::Value ret;
393- ret[" message" ] = " Started successfully!" ;
385+ ret[" message" ] = " Stopped successfully!" ;
394386 auto resp = cortex_utils::CreateCortexHttpJsonResponse (ret);
395387 resp->setStatusCode (k200OK);
396388 callback (resp);
0 commit comments