1414namespace commands {
1515
1616std::optional<std::string> SelectLocalModel (std::string host, int port,
17- const std::string& model_handle) {
17+ const std::string& model_handle,
18+ DatabaseService& db_service) {
1819 std::optional<std::string> model_id = model_handle;
19- cortex::db::Models modellist_handler;
20-
2120 if (model_handle.empty ()) {
22- auto all_local_models = modellist_handler .LoadModelList ();
21+ auto all_local_models = db_service .LoadModelList ();
2322 if (all_local_models.has_error () || all_local_models.value ().empty ()) {
2423 CLI_LOG (" No local models available!" );
2524 return std::nullopt ;
@@ -42,7 +41,7 @@ std::optional<std::string> SelectLocalModel(std::string host, int port,
4241 CLI_LOG (" Selected: " << selection.value ());
4342 }
4443 } else {
45- auto related_models_ids = modellist_handler .FindRelatedModel (model_handle);
44+ auto related_models_ids = db_service .FindRelatedModel (model_handle);
4645 if (related_models_ids.has_error () || related_models_ids.value ().empty ()) {
4746 auto result = ModelPullCmd ().Exec (host, port, model_handle);
4847 if (!result) {
@@ -69,19 +68,18 @@ std::optional<std::string> SelectLocalModel(std::string host, int port,
6968void RunCmd::Exec (bool run_detach,
7069 const std::unordered_map<std::string, std::string>& options) {
7170 std::optional<std::string> model_id =
72- SelectLocalModel (host_, port_, model_handle_);
71+ SelectLocalModel (host_, port_, model_handle_, *db_service_ );
7372 if (!model_id.has_value ()) {
7473 return ;
7574 }
7675
77- cortex::db::Models modellist_handler;
7876 config::YamlHandler yaml_handler;
7977 auto address = host_ + " :" + std::to_string (port_);
8078
8179 try {
8280 namespace fs = std::filesystem;
8381 namespace fmu = file_manager_utils;
84- auto model_entry = modellist_handler. GetModelInfo (*model_id);
82+ auto model_entry = db_service_-> GetModelInfo (*model_id);
8583 if (model_entry.has_error ()) {
8684 CLI_LOG (" Error: " + model_entry.error ());
8785 return ;
@@ -128,7 +126,7 @@ void RunCmd::Exec(bool run_detach,
128126 mc.engine .find (kLlamaEngine ) == std::string::npos) ||
129127 !commands::ModelStatusCmd ().IsLoaded (host_, port_, *model_id)) {
130128
131- auto res = commands::ModelStartCmd ()
129+ auto res = commands::ModelStartCmd (db_service_ )
132130 .Exec (host_, port_, *model_id, options,
133131 false /* print_success_log*/ );
134132 if (!res) {
@@ -144,7 +142,7 @@ void RunCmd::Exec(bool run_detach,
144142 << commands::GetCortexBinary () << " run " << *model_id
145143 << " ` for interactive chat shell" );
146144 } else {
147- ChatCompletionCmd ().Exec (host_, port_, *model_id, mc, " " );
145+ ChatCompletionCmd (db_service_ ).Exec (host_, port_, *model_id, mc, " " );
148146 }
149147 }
150148 } catch (const std::exception& e) {
0 commit comments