|
1 | 1 | #include "command_line_parser.h" |
2 | 2 | #include <memory> |
| 3 | +#include <optional> |
3 | 4 | #include "commands/chat_cmd.h" |
4 | 5 | #include "commands/chat_completion_cmd.h" |
5 | 6 | #include "commands/cortex_upd_cmd.h" |
@@ -82,27 +83,30 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { |
82 | 83 | // Check new update |
83 | 84 | #ifdef CORTEX_CPP_VERSION |
84 | 85 | if (cml_data_.check_upd) { |
85 | | - // TODO(sang) find a better way to handle |
86 | | - // This is an extremely ungly way to deal with connection |
87 | | - // hang when network down |
88 | | - std::atomic<bool> done = false; |
89 | | - std::thread t([&]() { |
90 | | - if (auto latest_version = |
91 | | - commands::CheckNewUpdate(commands::kTimeoutCheckUpdate); |
92 | | - latest_version.has_value() && *latest_version != CORTEX_CPP_VERSION) { |
93 | | - CLI_LOG("\nA new release of cortex is available: " |
94 | | - << CORTEX_CPP_VERSION << " -> " << *latest_version); |
95 | | - CLI_LOG("To upgrade, run: " << commands::GetRole() |
96 | | - << commands::GetCortexBinary() |
97 | | - << " update"); |
| 86 | + if (strcmp(CORTEX_CPP_VERSION, "default_version") != 0) { |
| 87 | + // TODO(sang) find a better way to handle |
| 88 | + // This is an extremely ugly way to deal with connection |
| 89 | + // hang when network down |
| 90 | + std::atomic<bool> done = false; |
| 91 | + std::thread t([&]() { |
| 92 | + if (auto latest_version = |
| 93 | + commands::CheckNewUpdate(commands::kTimeoutCheckUpdate); |
| 94 | + latest_version.has_value() && |
| 95 | + *latest_version != CORTEX_CPP_VERSION) { |
| 96 | + CLI_LOG("\nA new release of cortex is available: " |
| 97 | + << CORTEX_CPP_VERSION << " -> " << *latest_version); |
| 98 | + CLI_LOG("To upgrade, run: " << commands::GetRole() |
| 99 | + << commands::GetCortexBinary() |
| 100 | + << " update"); |
| 101 | + } |
| 102 | + done = true; |
| 103 | + }); |
| 104 | + // Do not wait for http connection timeout |
| 105 | + t.detach(); |
| 106 | + int retry = 10; |
| 107 | + while (!done && retry--) { |
| 108 | + std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 10); |
98 | 109 | } |
99 | | - done = true; |
100 | | - }); |
101 | | - // Do not wait for http connection timeout |
102 | | - t.detach(); |
103 | | - int retry = 10; |
104 | | - while (!done && retry--) { |
105 | | - std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 10); |
106 | 110 | } |
107 | 111 | } |
108 | 112 | #endif |
@@ -143,11 +147,6 @@ void CommandLineParser::SetupCommonCommands() { |
143 | 147 | run_cmd->callback([this, run_cmd] { |
144 | 148 | if (std::exchange(executed_, true)) |
145 | 149 | return; |
146 | | - if (cml_data_.model_id.empty()) { |
147 | | - CLI_LOG("[model_id] is required\n"); |
148 | | - CLI_LOG(run_cmd->help()); |
149 | | - return; |
150 | | - } |
151 | 150 | commands::RunCmd rc(cml_data_.config.apiServerHost, |
152 | 151 | std::stoi(cml_data_.config.apiServerPort), |
153 | 152 | cml_data_.model_id, download_service_); |
@@ -247,12 +246,19 @@ void CommandLineParser::SetupModelCommands() { |
247 | 246 |
|
248 | 247 | auto list_models_cmd = |
249 | 248 | models_cmd->add_subcommand("list", "List all models locally"); |
| 249 | + list_models_cmd->add_option("filter", cml_data_.filter, "Filter model id"); |
| 250 | + list_models_cmd->add_flag("-e,--engine", cml_data_.display_engine, |
| 251 | + "Display engine"); |
| 252 | + list_models_cmd->add_flag("-v,--version", cml_data_.display_version, |
| 253 | + "Display version"); |
250 | 254 | list_models_cmd->group(kSubcommands); |
251 | 255 | list_models_cmd->callback([this]() { |
252 | 256 | if (std::exchange(executed_, true)) |
253 | 257 | return; |
254 | 258 | commands::ModelListCmd().Exec(cml_data_.config.apiServerHost, |
255 | | - std::stoi(cml_data_.config.apiServerPort)); |
| 259 | + std::stoi(cml_data_.config.apiServerPort), |
| 260 | + cml_data_.filter, cml_data_.display_engine, |
| 261 | + cml_data_.display_version); |
256 | 262 | }); |
257 | 263 |
|
258 | 264 | auto get_models_cmd = |
|
0 commit comments