Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config_file_path and data_folder_path options #1482

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engine/commands/model_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void ModelUpdCmd::Exec(
namespace fs = std::filesystem;
namespace fmu = file_manager_utils;
try {
auto model_entry = model_list_utils_.GetModelInfo(model_handle_);
cortex::db::Models modellist_handler;
auto model_entry = modellist_handler.GetModelInfo(model_handle_);
if (model_entry.has_error()) {
CLI_LOG("Error: " + model_entry.error());
return;
Expand Down
1 change: 0 additions & 1 deletion engine/commands/model_upd_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class ModelUpdCmd {
std::string model_handle_;
config::ModelConfig model_config_;
config::YamlHandler yaml_handler_;
cortex::db::Models model_list_utils_;

void UpdateConfig(const std::string& key, const std::string& value);
void UpdateVectorField(const std::string& key, const std::string& value);
Expand Down
5 changes: 5 additions & 0 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {

app_.add_flag("--verbose", log_verbose, "Verbose logging");

// Logic is handled in main.cc, just for cli helper command
std::string path;
app_.add_option("--config_file_path", path, "Configuration file path");
app_.add_option("--data_folder_path", path, "Data folder path");

// cortex version
auto cb = [&](int c) {
#ifdef CORTEX_CPP_VERSION
Expand Down
5 changes: 2 additions & 3 deletions engine/database/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "utils/file_manager_utils.h"

namespace cortex::db {
const std::string kDefaultDbPath =
file_manager_utils::GetCortexDataPath().string() + "/cortex.db";
class Database {
public:
Database(Database const&) = delete;
Expand All @@ -22,7 +20,8 @@ class Database {

private:
Database()
: db_(kDefaultDbPath, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE) {}
: db_(file_manager_utils::GetCortexDataPath().string() + "/cortex.db",
SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE) {}
SQLite::Database db_;
};
} // namespace cortex::db
9 changes: 9 additions & 0 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ int main(int argc, char* argv[]) {
return 1;
}

for (int i = 0; i < argc; i++) {
if (strcmp(argv[i], "--config_file_path") == 0) {
file_manager_utils::cortex_config_file_path = argv[i + 1];

} else if(strcmp(argv[i], "--data_folder_path") == 0) {
file_manager_utils::cortex_data_folder_path = argv[i + 1];
}
}

{ file_manager_utils::CreateConfigFileIfNotExist(); }

// Delete temporary file if it exists
Expand Down
19 changes: 16 additions & 3 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ constexpr char kLogsLlamacppBaseName[] = "./logs/cortex.log";
constexpr char kLogsTensorrtllmBaseName[] = "./logs/cortex.log";
constexpr char kLogsOnnxBaseName[] = "./logs/cortex.log";

inline std::string cortex_config_file_path;

inline std::string cortex_data_folder_path;

inline std::filesystem::path GetExecutableFolderContainerPath() {
#if defined(__APPLE__) && defined(__MACH__)
char buffer[1024];
Expand Down Expand Up @@ -88,10 +92,15 @@ inline std::filesystem::path GetConfigurationPath() {
#ifndef CORTEX_VARIANT
#define CORTEX_VARIANT kProdVariant
#endif
std::string config_file_path{CORTEX_CONFIG_FILE_PATH};
std::string config_file_path;
if (cortex_config_file_path.empty()) {
config_file_path = CORTEX_CONFIG_FILE_PATH;
} else {
config_file_path = cortex_config_file_path;
}

if (config_file_path != kDefaultConfigurationPath) {
CTL_INF("Config file path: " + config_file_path);
// CTL_INF("Config file path: " + config_file_path);
return std::filesystem::path(config_file_path);
}

Expand Down Expand Up @@ -139,7 +148,11 @@ inline void CreateConfigFileIfNotExist() {

CLI_LOG("Config file not found. Creating one at " + config_path.string());
auto defaultDataFolderPath =
file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name;
cortex_data_folder_path.empty()
? file_manager_utils::GetHomeDirectoryPath() /
default_data_folder_name
: std::filesystem::path(cortex_data_folder_path) /
default_data_folder_name;
CLI_LOG("Default data folder path: " + defaultDataFolderPath.string());

auto config = config_yaml_utils::CortexConfig{
Expand Down
Loading