From 7134ddb06f41111413828ce536f1e1d895320207 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 28 Aug 2024 15:46:27 +0700 Subject: [PATCH 1/3] fix: gurantee lifetime for variables pass to cli callback --- engine/controllers/command_line_parser.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index b4f460261..20972cc27 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -20,7 +20,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { auto start_cmd = models_cmd->add_subcommand("start", "Start a model by ID"); std::string model_id; start_cmd->add_option("model_id", model_id, ""); - start_cmd->callback([&model_id]() { + start_cmd->callback([model_id]() { // TODO(sang) switch to .yaml when implement model manager config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + @@ -33,7 +33,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { auto stop_model_cmd = models_cmd->add_subcommand("stop", "Stop a model by ID"); stop_model_cmd->add_option("model_id", model_id, ""); - stop_model_cmd->callback([&model_id]() { + stop_model_cmd->callback([model_id]() { // TODO(sang) switch to .yaml when implement model manager config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + @@ -56,7 +56,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { "HuggingFace repositories. For available models, " "please visit https://huggingface.co/cortexso"); model_pull_cmd->add_option("model_id", model_id, ""); - model_pull_cmd->callback([&model_id]() { + model_pull_cmd->callback([model_id]() { commands::ModelPullCmd command(model_id); command.Exec(); }); @@ -76,7 +76,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { chat_cmd->add_option("-m,--message", msg, "Message to chat with model"); - chat_cmd->callback([&model_id, &msg] { + chat_cmd->callback([model_id, msg] { // TODO(sang) switch to .yaml when implement model manager config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + @@ -129,7 +129,7 @@ void CommandLineParser::EngineInstall(CLI::App* parent, "install", "Install " + engine_name + " engine"); install_cmd->add_option("-v, --version", version, "Engine version. Default will be latest"); - install_cmd->callback([&engine_name, &version] { + install_cmd->callback([engine_name, version] { commands::EngineInitCmd eic(engine_name, version); eic.Exec(); }); From 7ba9a1226e0ce9ad18837902559600c4ff6c9019 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 28 Aug 2024 17:45:53 +0700 Subject: [PATCH 2/3] chore: increase timeout to 60 mins --- .github/workflows/cortex-cpp-quality-gate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 092423821..39526d9a4 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -16,7 +16,7 @@ env: jobs: build-and-test: runs-on: ${{ matrix.runs-on }} - timeout-minutes: 40 + timeout-minutes: 60 strategy: fail-fast: false matrix: From fe7c1fd73339e983923837a351ab3aab5cb908ff Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 28 Aug 2024 19:14:28 +0700 Subject: [PATCH 3/3] fix: capture by reference --- engine/CMakeLists.txt | 2 +- engine/controllers/command_line_parser.cc | 29 ++++++++++++----------- engine/controllers/command_line_parser.h | 3 ++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index d18d28f2d..7ba095d6b 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -43,7 +43,7 @@ if(MSVC) $<$:/MT> #--| ) endif() - + if(LLAMA_CUDA) cmake_minimum_required(VERSION 3.17) diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 20972cc27..2c5f79c84 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -12,15 +12,16 @@ CommandLineParser::CommandLineParser() : app_("Cortex.cpp CLI") {} bool CommandLineParser::SetupCommand(int argc, char** argv) { + std::string model_id; + // Models group commands { auto models_cmd = app_.add_subcommand("models", "Subcommands for managing models"); auto start_cmd = models_cmd->add_subcommand("start", "Start a model by ID"); - std::string model_id; start_cmd->add_option("model_id", model_id, ""); - start_cmd->callback([model_id]() { + start_cmd->callback([&model_id]() { // TODO(sang) switch to .yaml when implement model manager config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + @@ -33,7 +34,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { auto stop_model_cmd = models_cmd->add_subcommand("stop", "Stop a model by ID"); stop_model_cmd->add_option("model_id", model_id, ""); - stop_model_cmd->callback([model_id]() { + stop_model_cmd->callback([&model_id]() { // TODO(sang) switch to .yaml when implement model manager config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + @@ -56,7 +57,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { "HuggingFace repositories. For available models, " "please visit https://huggingface.co/cortexso"); model_pull_cmd->add_option("model_id", model_id, ""); - model_pull_cmd->callback([model_id]() { + model_pull_cmd->callback([&model_id]() { commands::ModelPullCmd command(model_id); command.Exec(); }); @@ -67,16 +68,16 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { models_cmd->add_subcommand("update", "Update configuration of a model"); } + std::string msg; { auto chat_cmd = app_.add_subcommand("chat", "Send a chat request to a model"); - std::string model_id; + chat_cmd->add_option("model_id", model_id, ""); - std::string msg; chat_cmd->add_option("-m,--message", msg, "Message to chat with model"); - chat_cmd->callback([model_id, msg] { + chat_cmd->callback([&model_id, &msg] { // TODO(sang) switch to .yaml when implement model manager config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + @@ -92,15 +93,17 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { auto embeddings_cmd = app_.add_subcommand( "embeddings", "Creates an embedding vector representing the input text"); + // Default version is latest + std::string version{"latest"}; { // engines group commands auto engines_cmd = app_.add_subcommand("engines", "Get cortex engines"); auto list_engines_cmd = engines_cmd->add_subcommand("list", "List all cortex engines"); auto get_engine_cmd = engines_cmd->add_subcommand("get", "Get an engine"); - EngineInstall(engines_cmd, "cortex.llamacpp"); - EngineInstall(engines_cmd, "cortex.onnx"); - EngineInstall(engines_cmd, "cortex.tensorrt-llm"); + EngineInstall(engines_cmd, "cortex.llamacpp", version); + EngineInstall(engines_cmd, "cortex.onnx", version); + EngineInstall(engines_cmd, "cortex.tensorrt-llm", version); } auto run_cmd = @@ -119,17 +122,15 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { } void CommandLineParser::EngineInstall(CLI::App* parent, - const std::string& engine_name) { + const std::string& engine_name, std::string& version) { auto engine_cmd = parent->add_subcommand(engine_name, "Manage " + engine_name + " engine"); - // Default version is latest - std::string version{"latest"}; auto install_cmd = engine_cmd->add_subcommand( "install", "Install " + engine_name + " engine"); install_cmd->add_option("-v, --version", version, "Engine version. Default will be latest"); - install_cmd->callback([engine_name, version] { + install_cmd->callback([engine_name, &version] { commands::EngineInitCmd eic(engine_name, version); eic.Exec(); }); diff --git a/engine/controllers/command_line_parser.h b/engine/controllers/command_line_parser.h index e48ed31b0..b6695346e 100644 --- a/engine/controllers/command_line_parser.h +++ b/engine/controllers/command_line_parser.h @@ -9,7 +9,8 @@ class CommandLineParser { bool SetupCommand(int argc, char** argv); private: - void EngineInstall(CLI::App* parent, const std::string& engine_name); + void EngineInstall(CLI::App* parent, const std::string& engine_name, + std::string& version); CLI::App app_; }; \ No newline at end of file