@@ -78,7 +78,6 @@ cpp::result<DownloadTask, std::string> GetDownloadTask(
7878 .host = kHuggingFaceHost ,
7979 .pathParams = {" api" , " models" , " cortexso" , modelId, " tree" , branch}};
8080
81- httplib::Client cli (url.GetProtocolAndHost ());
8281 auto result = curl_utils::SimpleGetJson (url.ToFullPath ());
8382 if (result.has_error ()) {
8483 return cpp::fail (" Model " + modelId + " not found" );
@@ -546,6 +545,14 @@ cpp::result<void, std::string> ModelService::DeleteModel(
546545 cortex::db::Models modellist_handler;
547546 config::YamlHandler yaml_handler;
548547
548+ auto result = StopModel (model_handle);
549+ if (result.has_error ()) {
550+ CTL_INF (" Failed to stop model " << model_handle
551+ << " , error: " << result.error ());
552+ } else {
553+ CTL_INF (" Model " << model_handle << " stopped successfully" );
554+ }
555+
549556 try {
550557 auto model_entry = modellist_handler.GetModelInfo (model_handle);
551558 if (model_entry.has_error ()) {
@@ -590,7 +597,7 @@ cpp::result<void, std::string> ModelService::DeleteModel(
590597}
591598
592599cpp::result<bool , std::string> ModelService::StartModel (
593- const std::string& host, int port, const std::string& model_handle,
600+ const std::string& model_handle,
594601 const StartParameterOverride& params_override) {
595602 namespace fs = std::filesystem;
596603 namespace fmu = file_manager_utils;
@@ -627,7 +634,6 @@ cpp::result<bool, std::string> ModelService::StartModel(
627634 } else {
628635 bypass_stop_check_set_.insert (model_handle);
629636 }
630- httplib::Client cli (host + " :" + std::to_string (port));
631637
632638 json_data[" model" ] = model_handle;
633639 if (auto & cpt = params_override.custom_prompt_template ;
@@ -674,7 +680,7 @@ cpp::result<bool, std::string> ModelService::StartModel(
674680}
675681
676682cpp::result<bool , std::string> ModelService::StopModel (
677- const std::string& host, int port, const std::string& model_handle) {
683+ const std::string& model_handle) {
678684 namespace fs = std::filesystem;
679685 namespace fmu = file_manager_utils;
680686 cortex::db::Models modellist_handler;
@@ -683,7 +689,7 @@ cpp::result<bool, std::string> ModelService::StopModel(
683689 try {
684690 auto bypass_check = (bypass_stop_check_set_.find (model_handle) !=
685691 bypass_stop_check_set_.end ());
686- Json::Value json_data ;
692+ std::string engine_name = " " ;
687693 if (!bypass_check) {
688694 auto model_entry = modellist_handler.GetModelInfo (model_handle);
689695 if (model_entry.has_error ()) {
@@ -695,18 +701,13 @@ cpp::result<bool, std::string> ModelService::StopModel(
695701 fs::path (model_entry.value ().path_to_model_yaml ))
696702 .string ());
697703 auto mc = yaml_handler.GetModelConfig ();
698- json_data[ " engine " ] = mc.engine ;
704+ engine_name = mc.engine ;
699705 }
700-
701- httplib::Client cli (host + " :" + std::to_string (port));
702- json_data[" model" ] = model_handle;
703706 if (bypass_check) {
704- json_data[ " engine " ] = kLlamaEngine ;
707+ engine_name = kLlamaEngine ;
705708 }
706- CTL_INF (json_data.toStyledString ());
707709 assert (inference_svc_);
708- auto ir =
709- inference_svc_->UnloadModel (std::make_shared<Json::Value>(json_data));
710+ auto ir = inference_svc_->UnloadModel (engine_name, model_handle);
710711 auto status = std::get<0 >(ir)[" status_code" ].asInt ();
711712 auto data = std::get<1 >(ir);
712713 if (status == httplib::StatusCode::OK_200) {
@@ -725,7 +726,7 @@ cpp::result<bool, std::string> ModelService::StopModel(
725726}
726727
727728cpp::result<bool , std::string> ModelService::GetModelStatus (
728- const std::string& host, int port, const std::string& model_handle) {
729+ const std::string& model_handle) {
729730 namespace fs = std::filesystem;
730731 namespace fmu = file_manager_utils;
731732 cortex::db::Models modellist_handler;
@@ -743,29 +744,20 @@ cpp::result<bool, std::string> ModelService::GetModelStatus(
743744 .string ());
744745 auto mc = yaml_handler.GetModelConfig ();
745746
746- httplib::Client cli (host + " :" + std::to_string (port));
747-
748747 Json::Value root;
749748 root[" model" ] = model_handle;
750749 root[" engine" ] = mc.engine ;
751750
752- auto data_str = json_helper::DumpJsonString (root);
753-
754- auto res = cli.Post (" /inferences/server/modelstatus" , httplib::Headers (),
755- data_str.data (), data_str.size (), " application/json" );
756- if (res) {
757- if (res->status == httplib::StatusCode::OK_200) {
758- return true ;
759- } else {
760- CTL_INF (" Model failed to get model status with status code: "
761- << res->status );
762- return cpp::fail (" Model failed to get model status with status code: " +
763- std::to_string (res->status ));
764- }
751+ auto ir =
752+ inference_svc_->GetModelStatus (std::make_shared<Json::Value>(root));
753+ auto status = std::get<0 >(ir)[" status_code" ].asInt ();
754+ auto data = std::get<1 >(ir);
755+ if (status == httplib::StatusCode::OK_200) {
756+ return true ;
765757 } else {
766- auto err = res. error ( );
767- CTL_WRN ( " HTTP error: " << httplib::to_string (err));
768- return cpp::fail ( " HTTP error: " + httplib::to_string (err ));
758+ CTL_ERR ( " Model failed to get model status with status code: " << status );
759+ return cpp::fail ( " Model failed to get model status: " +
760+ data[ " message " ]. asString ( ));
769761 }
770762 } catch (const std::exception& e) {
771763 return cpp::fail (" Fail to get model status with ID '" + model_handle +
0 commit comments