Skip to content

Commit

Permalink
chore: add -DCORTEX_CONFIG_FILE_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
namchuai committed Sep 6, 2024
1 parent 703368b commit a5152b0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions engine/commands/engine_uninstall_cmd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include <array>

#include <string>

namespace commands {
Expand All @@ -11,8 +11,5 @@ class EngineUninstallCmd {

private:
std::string engine_;

static constexpr std::array<const char*, 3> supportedEngines_ = {
"cortex.llamacpp", "cortex.onnx", "cortex.tensorrt-llm"};
};
} // namespace commands
13 changes: 7 additions & 6 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions engine/controllers/command_line_parser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "CLI/CLI.hpp"
#include "services/engine_service.h"

class CommandLineParser {
public:
Expand All @@ -14,4 +15,5 @@ class CommandLineParser {
void EngineGet(CLI::App* parent);

CLI::App app_;
EngineService engine_service_;
};
2 changes: 1 addition & 1 deletion engine/utils/config_yaml_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline void CreateConfigFileIfNotExist() {
.port = kDefaultPort,
};
std::cout << "config: " << config.dataFolderPath << "\n";
DumpYamlConfig(config, config_path);
DumpYamlConfig(config, config_path.string());
}

inline CortexConfig FromYaml(const std::string& path,
Expand Down
6 changes: 6 additions & 0 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a5152b0

Please sign in to comment.