@@ -48,8 +48,11 @@ constexpr const auto kSubcommands = "Subcommands";
4848CommandLineParser::CommandLineParser ()
4949 : app_(" \n Cortex.cpp CLI\n " ),
5050 download_service_{std::make_shared<DownloadService>()},
51- model_service_{ModelService (download_service_)},
52- engine_service_{EngineService (download_service_)} {}
51+ dylib_path_manager_{std::make_shared<cortex::DylibPathManager>()},
52+ engine_service_{std::make_shared<EngineService>(download_service_,
53+ dylib_path_manager_)} {
54+ supported_engines_ = engine_service_->GetSupportedEngineNames ().value ();
55+ }
5356
5457bool CommandLineParser::SetupCommand (int argc, char ** argv) {
5558 app_.usage (" Usage:\n " + commands::GetCortexBinary () +
@@ -60,8 +63,6 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
6063
6164 SetupCommonCommands ();
6265
63- SetupInferenceCommands ();
64-
6566 SetupModelCommands ();
6667
6768 SetupEngineCommands ();
@@ -176,17 +177,11 @@ void CommandLineParser::SetupCommonCommands() {
176177 return ;
177178 commands::RunCmd rc (cml_data_.config .apiServerHost ,
178179 std::stoi (cml_data_.config .apiServerPort ),
179- cml_data_.model_id , download_service_ );
180+ cml_data_.model_id , engine_service_ );
180181 rc.Exec (cml_data_.run_detach , run_settings_);
181182 });
182183}
183184
184- void CommandLineParser::SetupInferenceCommands () {
185- // auto embeddings_cmd = app_.add_subcommand(
186- // "embeddings", "Creates an embedding vector representing the input text");
187- // embeddings_cmd->group(kInferenceGroup);
188- }
189-
190185void CommandLineParser::SetupModelCommands () {
191186 // Models group commands
192187 auto models_cmd =
@@ -476,7 +471,7 @@ void CommandLineParser::SetupEngineCommands() {
476471 list_engines_cmd->callback ([this ]() {
477472 if (std::exchange (executed_, true ))
478473 return ;
479- commands::EngineListCmd command ;
474+ auto command = commands::EngineListCmd (engine_service_) ;
480475 command.Exec (cml_data_.config .apiServerHost ,
481476 std::stoi (cml_data_.config .apiServerPort ));
482477 });
@@ -493,9 +488,9 @@ void CommandLineParser::SetupEngineCommands() {
493488 CLI_LOG (install_cmd->help ());
494489 }
495490 });
496- for ( const auto & engine : engine_service_. kSupportEngines ) {
497- std::string engine_name{engine};
498- EngineInstall (install_cmd, engine_name , cml_data_.engine_version ,
491+
492+ for ( const auto & engine : supported_engines_) {
493+ EngineInstall (install_cmd, engine , cml_data_.engine_version ,
499494 cml_data_.engine_src );
500495 }
501496
@@ -512,9 +507,8 @@ void CommandLineParser::SetupEngineCommands() {
512507 }
513508 });
514509 uninstall_cmd->group (kSubcommands );
515- for (auto & engine : engine_service_.kSupportEngines ) {
516- std::string engine_name{engine};
517- EngineUninstall (uninstall_cmd, engine_name);
510+ for (const auto & engine : supported_engines_) {
511+ EngineUninstall (uninstall_cmd, engine);
518512 }
519513
520514 auto engine_upd_cmd = engines_cmd->add_subcommand (" update" , " Update engine" );
@@ -529,9 +523,8 @@ void CommandLineParser::SetupEngineCommands() {
529523 }
530524 });
531525 engine_upd_cmd->group (kSubcommands );
532- for (auto & engine : engine_service_.kSupportEngines ) {
533- std::string engine_name{engine};
534- EngineUpdate (engine_upd_cmd, engine_name);
526+ for (const auto & engine : supported_engines_) {
527+ EngineUpdate (engine_upd_cmd, engine);
535528 }
536529
537530 auto engine_use_cmd =
@@ -547,9 +540,8 @@ void CommandLineParser::SetupEngineCommands() {
547540 }
548541 });
549542 engine_use_cmd->group (kSubcommands );
550- for (auto & engine : engine_service_.kSupportEngines ) {
551- std::string engine_name{engine};
552- EngineUse (engine_use_cmd, engine_name);
543+ for (const auto & engine : supported_engines_) {
544+ EngineUse (engine_use_cmd, engine);
553545 }
554546
555547 auto engine_load_cmd = engines_cmd->add_subcommand (" load" , " Load engine" );
@@ -564,9 +556,8 @@ void CommandLineParser::SetupEngineCommands() {
564556 }
565557 });
566558 engine_load_cmd->group (kSubcommands );
567- for (auto & engine : engine_service_.kSupportEngines ) {
568- std::string engine_name{engine};
569- EngineLoad (engine_load_cmd, engine_name);
559+ for (const auto & engine : supported_engines_) {
560+ EngineLoad (engine_load_cmd, engine);
570561 }
571562
572563 auto engine_unload_cmd =
@@ -582,9 +573,8 @@ void CommandLineParser::SetupEngineCommands() {
582573 }
583574 });
584575 engine_unload_cmd->group (kSubcommands );
585- for (auto & engine : engine_service_.kSupportEngines ) {
586- std::string engine_name{engine};
587- EngineUnload (engine_unload_cmd, engine_name);
576+ for (const auto & engine : supported_engines_) {
577+ EngineUnload (engine_unload_cmd, engine);
588578 }
589579
590580 EngineGet (engines_cmd);
@@ -756,7 +746,7 @@ void CommandLineParser::EngineInstall(CLI::App* parent,
756746 return ;
757747 try {
758748 commands::EngineInstallCmd (
759- download_service_ , cml_data_.config .apiServerHost ,
749+ engine_service_ , cml_data_.config .apiServerHost ,
760750 std::stoi (cml_data_.config .apiServerPort ), cml_data_.show_menu )
761751 .Exec (engine_name, version, src);
762752 } catch (const std::exception& e) {
@@ -878,20 +868,19 @@ void CommandLineParser::EngineGet(CLI::App* parent) {
878868 }
879869 });
880870
881- for (auto & engine : engine_service_.kSupportEngines ) {
882- std::string engine_name{engine};
883- std::string desc = " Get " + engine_name + " status" ;
871+ for (const auto & engine : supported_engines_) {
872+ std::string desc = " Get " + engine + " status" ;
884873
885- auto engine_get_cmd = get_cmd->add_subcommand (engine_name , desc);
874+ auto engine_get_cmd = get_cmd->add_subcommand (engine , desc);
886875 engine_get_cmd->usage (" Usage:\n " + commands::GetCortexBinary () +
887- " engines get " + engine_name + " [options]" );
876+ " engines get " + engine + " [options]" );
888877 engine_get_cmd->group (kEngineGroup );
889- engine_get_cmd->callback ([this , engine_name ] {
878+ engine_get_cmd->callback ([this , engine ] {
890879 if (std::exchange (executed_, true ))
891880 return ;
892881 commands::EngineGetCmd ().Exec (cml_data_.config .apiServerHost ,
893882 std::stoi (cml_data_.config .apiServerPort ),
894- engine_name );
883+ engine );
895884 });
896885 }
897886}
0 commit comments