diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index 2735501dc..ed6491e94 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -59,6 +59,10 @@ if(DEBUG) add_compile_definitions(ALLOW_ALL_CORS) endif() +if(NOT DEFINED CORTEX_CONFIG_FILE_PATH) + set(CORTEX_CONFIG_FILE_PATH "user_home") +endif() + if(NOT DEFINED CORTEX_CPP_VERSION) set(CORTEX_CPP_VERSION "default_version") endif() @@ -80,6 +84,7 @@ if(DEFINED CMAKE_JS_INC) endif() add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}") +add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}") option(CMAKE_BUILD_TEST "Enable testing" OFF) if(CMAKE_BUILD_TEST) diff --git a/engine/commands/engine_uninstall_cmd.h b/engine/commands/engine_uninstall_cmd.h index 94c1016e7..a8a760403 100644 --- a/engine/commands/engine_uninstall_cmd.h +++ b/engine/commands/engine_uninstall_cmd.h @@ -1,5 +1,5 @@ #pragma once -#include + #include namespace commands { @@ -11,8 +11,5 @@ class EngineUninstallCmd { private: std::string engine_; - - static constexpr std::array supportedEngines_ = { - "cortex.llamacpp", "cortex.onnx", "cortex.tensorrt-llm"}; }; } // namespace commands diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index e90f99873..17a8afd80 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -17,7 +17,8 @@ #include "utils/cortex_utils.h" #include "utils/logging_utils.h" -CommandLineParser::CommandLineParser() : app_("Cortex.cpp CLI") {} +CommandLineParser::CommandLineParser() + : app_("Cortex.cpp CLI"), engine_service_{EngineService()} {} bool CommandLineParser::SetupCommand(int argc, char** argv) { std::string model_id; @@ -127,9 +128,10 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { command.Exec(); }); - EngineManagement(engines_cmd, "cortex.llamacpp", version); - EngineManagement(engines_cmd, "cortex.onnx", version); - EngineManagement(engines_cmd, "cortex.tensorrt-llm", version); + for (auto& engine : engine_service_.kSupportEngines) { + std::string engine_name{engine}; + EngineManagement(engines_cmd, engine_name, version); + } EngineGet(engines_cmd); } @@ -186,9 +188,8 @@ void CommandLineParser::EngineManagement(CLI::App* parent, void CommandLineParser::EngineGet(CLI::App* parent) { auto get_cmd = parent->add_subcommand("get", "Get an engine info"); - auto engine_service = EngineService(); - for (auto& engine : engine_service.kSupportEngines) { + for (auto& engine : engine_service_.kSupportEngines) { std::string engine_name{engine}; std::string desc = "Get " + engine_name + " status"; diff --git a/engine/controllers/command_line_parser.h b/engine/controllers/command_line_parser.h index a15aa0529..0fa89e241 100644 --- a/engine/controllers/command_line_parser.h +++ b/engine/controllers/command_line_parser.h @@ -1,6 +1,7 @@ #pragma once #include "CLI/CLI.hpp" +#include "services/engine_service.h" class CommandLineParser { public: @@ -14,4 +15,5 @@ class CommandLineParser { void EngineGet(CLI::App* parent); CLI::App app_; + EngineService engine_service_; }; diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index 71a3a5add..c958ec8e0 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -15,6 +15,7 @@ namespace file_manager_utils { constexpr std::string_view kCortexConfigurationFileName = ".cortexrc"; +constexpr std::string_view kDefaultConfigurationPath = "user_home"; inline std::filesystem::path GetExecutableFolderContainerPath() { #if defined(__APPLE__) && defined(__MACH__) @@ -73,6 +74,11 @@ inline std::filesystem::path GetHomeDirectoryPath() { } inline std::filesystem::path GetConfigurationPath() { + std::string config_file_path{CORTEX_CONFIG_FILE_PATH}; + + if (config_file_path != kDefaultConfigurationPath) { + return std::filesystem::path(config_file_path); + } auto home_path = GetHomeDirectoryPath(); auto configuration_path = home_path / kCortexConfigurationFileName; return configuration_path;