|
28 | 28 | #include "graph_export/image_generation_graph_cli_parser.hpp"
|
29 | 29 | #include "ovms_exit_codes.hpp"
|
30 | 30 | #include "filesystem.hpp"
|
| 31 | +#include "localfilesystem.hpp" |
31 | 32 | #include "stringutils.hpp"
|
32 | 33 | #include "version.hpp"
|
33 | 34 |
|
34 | 35 | namespace ovms {
|
35 | 36 |
|
36 | 37 | constexpr const char* CONFIG_MANAGEMENT_HELP_GROUP{"config management"};
|
37 | 38 |
|
| 39 | +std::string getConfigPath(const std::string& configPath) { |
| 40 | + bool isDir = false; |
| 41 | + auto status = LocalFileSystem::isDir(configPath, &isDir); |
| 42 | + if (!status.ok()) { |
| 43 | + throw std::logic_error("Invalid path for the config: " + configPath); |
| 44 | + } |
| 45 | + if (isDir) { |
| 46 | + return FileSystem::joinPath({configPath, "config.json"}); |
| 47 | + } |
| 48 | + return configPath; |
| 49 | +} |
| 50 | + |
38 | 51 | void CLIParser::parse(int argc, char** argv) {
|
39 | 52 | try {
|
40 | 53 | options = std::make_unique<cxxopts::Options>(argv[0], "OpenVINO Model Server");
|
| 54 | + auto configOptions = std::make_unique<cxxopts::Options>("ovms --model_name <MODEL_NAME> --add_to_config <CONFIG_PATH> --model_repository_path <MODEL_REPO_PATH> \n ovms --model_path <MODEL_PATH> --model_name <MODEL_NAME> --add_to_config <CONFIG_PATH> \n ovms --remove_from_config <CONFIG_PATH> --model_name <MODEL_NAME>", "config management commands:"); |
41 | 55 | // Adding this option to parse unrecognised options in another parser
|
42 | 56 | options->allow_unrecognised_options();
|
43 | 57 |
|
@@ -254,6 +268,33 @@ void CLIParser::parse(int argc, char** argv) {
|
254 | 268 | "Determines how many sequences can be processed concurrently by one model instance. When that value is reached, attempt to start a new sequence will result in error.",
|
255 | 269 | cxxopts::value<uint32_t>(),
|
256 | 270 | "MAX_SEQUENCE_NUMBER");
|
| 271 | + configOptions->custom_help(""); |
| 272 | + configOptions->add_options(CONFIG_MANAGEMENT_HELP_GROUP) |
| 273 | + ("list_models", |
| 274 | + "Directive to show available servables in models repository", |
| 275 | + cxxopts::value<bool>()->default_value("false"), |
| 276 | + "LIST_MODELS") |
| 277 | + ("add_to_config", |
| 278 | + "Either path to directory containing config.json file for OVMS, or path to ovms configuration file, to add specific model to. This parameter should be executed with --model_name and either with --model_path or --model_repository_path.", |
| 279 | + cxxopts::value<std::string>(), |
| 280 | + "ADD_TO_CONFIG") |
| 281 | + ("remove_from_config", |
| 282 | + "Either path to directory containing config.json file for OVMS, or path to ovms configuration file, to remove specific model from. This parameter should be executed with --model_name to specify which model we want to remove.", |
| 283 | + cxxopts::value<std::string>(), |
| 284 | + "REMOVE_FROM_CONFIG") |
| 285 | + ("model_repository_path", |
| 286 | + "Absolute or relative path from the config directory to the model repository", |
| 287 | + cxxopts::value<std::string>(), |
| 288 | + "MODEL_REPOSITORY_PATH") |
| 289 | + ("model_path", |
| 290 | + "Absolute or relative path from the config directory to the model. By default is a combination of the model_repository_path and model_name.", |
| 291 | + cxxopts::value<std::string>(), |
| 292 | + "MODEL_PATH") |
| 293 | + ("model_name", |
| 294 | + "Name of the model", |
| 295 | + cxxopts::value<std::string>(), |
| 296 | + "MODEL_NAME"); |
| 297 | + |
257 | 298 | result = std::make_unique<cxxopts::ParseResult>(options->parse(argc, argv));
|
258 | 299 |
|
259 | 300 | // HF pull mode or pull and start mode
|
@@ -358,7 +399,8 @@ void CLIParser::parse(int argc, char** argv) {
|
358 | 399 | }
|
359 | 400 |
|
360 | 401 | if (result->count("help") || result->arguments().size() == 0) {
|
361 |
| - std::cout << options->help({"", "multi model", "single model", "pull hf model", CONFIG_MANAGEMENT_HELP_GROUP}) << std::endl; |
| 402 | + std::cout << options->help({"", "multi model", "single model", "pull hf model"}) << std::endl; |
| 403 | + std::cout << configOptions->help({CONFIG_MANAGEMENT_HELP_GROUP}) << std::endl; |
362 | 404 | GraphCLIParser parser1;
|
363 | 405 | RerankGraphCLIParser parser2;
|
364 | 406 | EmbeddingsGraphCLIParser parser3;
|
@@ -461,7 +503,7 @@ void CLIParser::prepareModel(ModelsSettingsImpl& modelsSettings, HFSettingsImpl&
|
461 | 503 | }
|
462 | 504 | if (result->count("model_path")) {
|
463 | 505 | modelsSettings.modelPath = result->operator[]("model_path").as<std::string>();
|
464 |
| - modelsSettings.userSetSingleModelArguments.push_back("model_name"); |
| 506 | + modelsSettings.userSetSingleModelArguments.push_back("model_path"); |
465 | 507 | }
|
466 | 508 | if (result->count("max_sequence_number")) {
|
467 | 509 | modelsSettings.maxSequenceNumber = result->operator[]("max_sequence_number").as<uint32_t>();
|
@@ -637,9 +679,9 @@ void CLIParser::prepareConfigExport(ModelsSettingsImpl& modelsSettings) {
|
637 | 679 | modelsSettings.modelPath = FileSystem::joinPath({result->operator[]("model_repository_path").as<std::string>(), modelsSettings.modelName});
|
638 | 680 | }
|
639 | 681 | if (result->count("add_to_config")) {
|
640 |
| - modelsSettings.configPath = result->operator[]("add_to_config").as<std::string>(); |
| 682 | + modelsSettings.configPath = ovms::getConfigPath(result->operator[]("add_to_config").as<std::string>()); |
641 | 683 | } else if (result->count("remove_from_config")) {
|
642 |
| - modelsSettings.configPath = result->operator[]("remove_from_config").as<std::string>(); |
| 684 | + modelsSettings.configPath = ovms::getConfigPath(result->operator[]("remove_from_config").as<std::string>()); |
643 | 685 | }
|
644 | 686 | }
|
645 | 687 |
|
|
0 commit comments