@@ -59,6 +59,8 @@ void Models::PullModel(const HttpRequestPtr& req,
5959void Models::ListModel (
6060 const HttpRequestPtr& req,
6161 std::function<void (const HttpResponsePtr&)>&& callback) const {
62+ namespace fs = std::filesystem;
63+ namespace fmu = file_manager_utils;
6264 Json::Value ret;
6365 ret[" object" ] = " list" ;
6466 Json::Value data (Json::arrayValue);
@@ -73,8 +75,10 @@ void Models::ListModel(
7375 for (const auto & model_entry : list_entry.value ()) {
7476 // auto model_entry = modellist_handler.GetModelInfo(model_handle);
7577 try {
76-
77- yaml_handler.ModelConfigFromFile (model_entry.path_to_model_yaml );
78+ yaml_handler.ModelConfigFromFile (
79+ fmu::ToAbsoluteCortexDataPath (
80+ fs::path (model_entry.path_to_model_yaml ))
81+ .string ());
7882 auto model_config = yaml_handler.GetModelConfig ();
7983 Json::Value obj = model_config.ToJson ();
8084
@@ -106,6 +110,8 @@ void Models::ListModel(
106110void Models::GetModel (const HttpRequestPtr& req,
107111 std::function<void (const HttpResponsePtr&)>&& callback,
108112 const std::string& model_id) const {
113+ namespace fs = std::filesystem;
114+ namespace fmu = file_manager_utils;
109115 LOG_DEBUG << " GetModel, Model handle: " << model_id;
110116 Json::Value ret;
111117 ret[" object" ] = " list" ;
@@ -125,7 +131,10 @@ void Models::GetModel(const HttpRequestPtr& req,
125131 callback (resp);
126132 return ;
127133 }
128- yaml_handler.ModelConfigFromFile (model_entry.value ().path_to_model_yaml );
134+ yaml_handler.ModelConfigFromFile (
135+ fmu::ToAbsoluteCortexDataPath (
136+ fs::path (model_entry.value ().path_to_model_yaml ))
137+ .string ());
129138 auto model_config = yaml_handler.GetModelConfig ();
130139
131140 Json::Value obj = model_config.ToJson ();
@@ -137,8 +146,8 @@ void Models::GetModel(const HttpRequestPtr& req,
137146 resp->setStatusCode (k200OK);
138147 callback (resp);
139148 } catch (const std::exception& e) {
140- std::string message = " Fail to get model information with ID ' " +
141- model_id + " ': " + e.what ();
149+ std::string message =
150+ " Fail to get model information with ID ' " + model_id + " ': " + e.what ();
142151 LOG_ERROR << message;
143152 ret[" data" ] = data;
144153 ret[" result" ] = " Fail to get model information" ;
@@ -171,16 +180,20 @@ void Models::DeleteModel(const HttpRequestPtr& req,
171180void Models::UpdateModel (const HttpRequestPtr& req,
172181 std::function<void (const HttpResponsePtr&)>&& callback,
173182 const std::string& model_id) const {
183+ namespace fs = std::filesystem;
184+ namespace fmu = file_manager_utils;
174185 auto json_body = *(req->getJsonObject ());
175186 try {
176187 cortex::db::Models model_list_utils;
177188 auto model_entry = model_list_utils.GetModelInfo (model_id);
178189 config::YamlHandler yaml_handler;
179- yaml_handler.ModelConfigFromFile (model_entry.value ().path_to_model_yaml );
190+ auto yaml_fp = fmu::ToAbsoluteCortexDataPath (
191+ fs::path (model_entry.value ().path_to_model_yaml ));
192+ yaml_handler.ModelConfigFromFile (yaml_fp.string ());
180193 config::ModelConfig model_config = yaml_handler.GetModelConfig ();
181194 model_config.FromJson (json_body);
182195 yaml_handler.UpdateModelConfig (model_config);
183- yaml_handler.WriteYamlFile (model_entry. value (). path_to_model_yaml );
196+ yaml_handler.WriteYamlFile (yaml_fp. string () );
184197 std::string message = " Successfully update model ID '" + model_id +
185198 " ': " + json_body.toStyledString ();
186199 LOG_INFO << message;
@@ -210,6 +223,8 @@ void Models::UpdateModel(const HttpRequestPtr& req,
210223void Models::ImportModel (
211224 const HttpRequestPtr& req,
212225 std::function<void (const HttpResponsePtr&)>&& callback) const {
226+ namespace fs = std::filesystem;
227+ namespace fmu = file_manager_utils;
213228 if (!http_util::HasFieldInReq (req, callback, " model" ) ||
214229 !http_util::HasFieldInReq (req, callback, " modelPath" )) {
215230 return ;
@@ -219,14 +234,18 @@ void Models::ImportModel(
219234 config::GGUFHandler gguf_handler;
220235 config::YamlHandler yaml_handler;
221236 cortex::db::Models modellist_utils_obj;
222-
223237 std::string model_yaml_path = (file_manager_utils::GetModelsContainerPath () /
224238 std::filesystem::path (" imported" ) /
225239 std::filesystem::path (modelHandle + " .yml" ))
226240 .string ();
227- cortex::db::ModelEntry model_entry{modelHandle, " local" , " imported" ,
228- model_yaml_path, modelHandle};
241+
229242 try {
243+ // Use relative path for model_yaml_path. In case of import, we use absolute path for model
244+ auto yaml_rel_path =
245+ fmu::ToRelativeCortexDataPath (fs::path (model_yaml_path));
246+ cortex::db::ModelEntry model_entry{modelHandle, " local" , " imported" ,
247+ yaml_rel_path.string (), modelHandle};
248+
230249 std::filesystem::create_directories (
231250 std::filesystem::path (model_yaml_path).parent_path ());
232251 gguf_handler.Parse (modelPath);
@@ -295,13 +314,13 @@ void Models::SetModelAlias(
295314 if (result.has_error ()) {
296315 std::string message = result.error ();
297316 LOG_ERROR << message;
298- Json::Value ret;
299- ret[" result" ] = " Set alias failed!" ;
300- ret[" modelHandle" ] = model_handle;
301- ret[" message" ] = message;
302- auto resp = cortex_utils::CreateCortexHttpJsonResponse (ret);
303- resp->setStatusCode (k400BadRequest);
304- callback (resp);
317+ Json::Value ret;
318+ ret[" result" ] = " Set alias failed!" ;
319+ ret[" modelHandle" ] = model_handle;
320+ ret[" message" ] = message;
321+ auto resp = cortex_utils::CreateCortexHttpJsonResponse (ret);
322+ resp->setStatusCode (k400BadRequest);
323+ callback (resp);
305324 } else {
306325 if (result.value ()) {
307326 std::string message = " Successfully set model alias '" + model_alias +
0 commit comments