From 109d1d1414f6a6e79cbf6d8b672533abd3c40d96 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 30 Aug 2024 07:48:43 +0700 Subject: [PATCH] fix: use model_id.yaml for model info --- engine/commands/chat_cmd.cc | 4 +++- engine/controllers/command_line_parser.cc | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/engine/commands/chat_cmd.cc b/engine/commands/chat_cmd.cc index 2c00053c9..6de88ed28 100644 --- a/engine/commands/chat_cmd.cc +++ b/engine/commands/chat_cmd.cc @@ -34,7 +34,8 @@ ChatCmd::ChatCmd(std::string host, int port, const config::ModelConfig& mc) void ChatCmd::Exec(std::string msg) { auto address = host_ + ":" + std::to_string(port_); // Check if model is loaded - { + // TODO(sang) only llamacpp support modelstatus for now + if (mc_.engine.find("llamacpp") != std::string::npos) { httplib::Client cli(address); nlohmann::json json_data; json_data["model"] = mc_.name; @@ -56,6 +57,7 @@ void ChatCmd::Exec(std::string msg) { return; } } + // Some instruction for user here std::cout << "Inorder to exit, type `exit()`" << std::endl; // Model is loaded, start to chat diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 835445501..ec4c05f37 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -25,10 +25,12 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { auto start_cmd = models_cmd->add_subcommand("start", "Start a model by ID"); start_cmd->add_option("model_id", model_id, ""); start_cmd->callback([&model_id]() { - // TODO(sang) switch to .yaml when implement model manager + commands::CmdInfo ci(model_id); + std::string model_file = + ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + - "/models/" + model_id + "/model.yml"); + "/models/" + model_file + ".yaml"); commands::ModelStartCmd msc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); msc.Exec(); @@ -38,10 +40,12 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { 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]() { - // TODO(sang) switch to .yaml when implement model manager + commands::CmdInfo ci(model_id); + std::string model_file = + ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + - "/models/" + model_id + "/model.yml"); + "/models/" + model_file + ".yaml"); commands::StopModelCmd smc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); smc.Exec(); @@ -90,10 +94,12 @@ 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] { - // TODO(sang) switch to .yaml when implement model manager + commands::CmdInfo ci(model_id); + std::string model_file = + ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch; config::YamlHandler yaml_handler; yaml_handler.ModelConfigFromFile(cortex_utils::GetCurrentPath() + - "/models/" + model_id + "/model.yml"); + "/models/" + model_file + ".yaml"); commands::ChatCmd cc("127.0.0.1", 3928, yaml_handler.GetModelConfig()); cc.Exec(msg); });