Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion src/capi_frontend/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ DLL_PUBLIC OVMS_Status* OVMS_ServerStartFromConfigurationFile(OVMS_Server* serve
ovms::Server* srv = reinterpret_cast<ovms::Server*>(server);
ovms::ServerSettingsImpl* serverSettings = reinterpret_cast<ovms::ServerSettingsImpl*>(server_settings);
ovms::ModelsSettingsImpl* modelsSettings = reinterpret_cast<ovms::ModelsSettingsImpl*>(models_settings);
auto res = srv->start(serverSettings, modelsSettings);
auto res = srv->startFromSettings(serverSettings, modelsSettings);
if (res.ok()) {
std::atexit(server_atexit_handler);
return nullptr;
Expand Down
82 changes: 42 additions & 40 deletions src/cli_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ std::string getConfigPath(const std::string& configPath) {
return configPath;
}

void CLIParser::parse(int argc, char** argv) {
std::variant<bool, std::pair<int, std::string>> CLIParser::parse(int argc, char** argv) {
std::stringstream ss;
try {
options = std::make_unique<cxxopts::Options>(argv[0], "OpenVINO Model Server");
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:");
Expand Down Expand Up @@ -353,78 +354,78 @@ void CLIParser::parse(int argc, char** argv) {
break;
}
case UNKNOWN_GRAPH: {
std::cerr << "error parsing options - --task parameter unsupported value: " + result->operator[]("task").as<std::string>();
exit(OVMS_EX_USAGE);
ss << "error parsing options - --task parameter unsupported value: " + result->operator[]("task").as<std::string>();
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
}
} else {
std::cerr << "error parsing options - --task parameter wasn't passed";
exit(OVMS_EX_USAGE);
ss << "error parsing options - --task parameter wasn't passed";
return std::make_pair(OVMS_EX_USAGE, ss.str());
}

if (unmatchedOptions.size()) {
std::cerr << "task: " << enumToString(task) << " - error parsing options - unmatched arguments : ";
ss << "task: " << enumToString(task) << " - error parsing options - unmatched arguments : ";
for (auto& argument : unmatchedOptions) {
std::cerr << argument << ", ";
ss << argument << ", ";
}
std::cerr << std::endl;
exit(OVMS_EX_USAGE);
ss << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
} else if (result->unmatched().size()){
std::cerr << "error parsing options - unmatched arguments: ";
ss << "error parsing options - unmatched arguments: ";
for (auto& argument : result->unmatched()) {
std::cerr << argument << ", ";
ss << argument << ", ";
}
std::cerr << std::endl;
exit(OVMS_EX_USAGE);
ss << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (isHFPullOrPullAndStart(this->result) && result->count("list_models")) {
std::cerr << "error parsing options - --list_models cannot be used with --pull or --task" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --list_models cannot be used with --pull or --task" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (isHFPullOrPullAndStart(this->result) && result->count("remove_from_config")) {
std::cerr << "error parsing options - --remove_from_config cannot be used with --pull or --task" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --remove_from_config cannot be used with --pull or --task" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (isHFPullOrPullAndStart(this->result) && result->count("add_to_config")) {
std::cerr << "error parsing options - --add_to_config cannot be used with --pull or --task" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --add_to_config cannot be used with --pull or --task" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (result->count("add_to_config") && result->count("list_models")) {
std::cerr << "error parsing options - --list_models cannot be used with --add_to_config" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --list_models cannot be used with --add_to_config" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (result->count("remove_from_config") && result->count("list_models")) {
std::cerr << "error parsing options - --list_models cannot be used with --remove_from_config" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --list_models cannot be used with --remove_from_config" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (result->count("add_to_config") && result->count("model_repository_path") && result->count("model_path")) {
std::cerr << "error parsing options - --model_repository_path cannot be used with --model_path" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --model_repository_path cannot be used with --model_path" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (result->count("remove_from_config") && result->count("model_repository_path")) {
std::cerr << "error parsing options - --model_repository_path cannot be used with --remove_from_config" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --model_repository_path cannot be used with --remove_from_config" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
if (result->count("remove_from_config") && result->count("model_path")) {
std::cerr << "error parsing options - --model_path cannot be used with --remove_from_config" << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options - --model_path cannot be used with --remove_from_config" << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
#pragma warning(push)
#pragma warning(disable : 4129)
if (result->count("version")) {
std::string project_name(PROJECT_NAME);
std::string project_version(PROJECT_VERSION);
std::cout << project_name + " " + project_version << std::endl;
std::cout << "OpenVINO backend " << OPENVINO_NAME << std::endl;
std::cout << "Bazel build flags: " << BAZEL_BUILD_FLAGS << std::endl;
ss << project_name + " " + project_version << std::endl;
ss << "OpenVINO backend " << OPENVINO_NAME << std::endl;
ss << "Bazel build flags: " << BAZEL_BUILD_FLAGS << std::endl;
#pragma warning(pop)
exit(OVMS_EX_OK);
return std::make_pair(OVMS_EX_OK, ss.str());
}

if (result->count("help") || result->arguments().size() == 0) {
std::cout << options->help({"", "multi model", "single model", "pull hf model"}) << std::endl;
std::cout << configOptions->help({CONFIG_MANAGEMENT_HELP_GROUP}) << std::endl;
ss << options->help({"", "multi model", "single model", "pull hf model"}) << std::endl;
ss << configOptions->help({CONFIG_MANAGEMENT_HELP_GROUP}) << std::endl;
GraphCLIParser parser1;
RerankGraphCLIParser parser2;
EmbeddingsGraphCLIParser parser3;
Expand All @@ -435,11 +436,13 @@ void CLIParser::parse(int argc, char** argv) {
parser2.printHelp();
parser3.printHelp();
imageGenParser.printHelp();
exit(OVMS_EX_OK);
return std::make_pair(OVMS_EX_OK, ss.str());
}

return true;
} catch (const std::exception& e) {
std::cerr << "error parsing options: " << e.what() << std::endl;
exit(OVMS_EX_USAGE);
ss << "error parsing options: " << e.what() << std::endl;
return std::make_pair(OVMS_EX_USAGE, ss.str());
}
}

Expand Down Expand Up @@ -532,8 +535,7 @@ void CLIParser::prepareServer(ServerSettingsImpl& serverSettings) {
}
file.close();
} else {
std::cerr << "Error reading API key file: Unable to open file " << apiKeyFile << std::endl;
exit(OVMS_EX_USAGE);
throw std::filesystem::filesystem_error("Error reading API key file: Unable to open file ", apiKeyFile, std::error_code(2, std::generic_category()));
}
} else {
const char* envApiKey = std::getenv(API_KEY_ENV_VAR);
Expand Down
3 changes: 2 additions & 1 deletion src/cli_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <memory>
#include <string>
#include <utility>
#include <variant>

#include <cxxopts.hpp>
Expand All @@ -40,7 +41,7 @@ class CLIParser {

public:
CLIParser() = default;
void parse(int argc, char** argv);
std::variant<bool, std::pair<int, std::string>> parse(int argc, char** argv);
void prepare(ServerSettingsImpl*, ModelsSettingsImpl*);

protected:
Expand Down
17 changes: 14 additions & 3 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <filesystem>
#include <limits>
#include <regex>
#include <utility>
#include <thread>
#include <vector>

Expand Down Expand Up @@ -49,11 +50,21 @@ const size_t DEFAULT_GRPC_MEMORY_QUOTA = (size_t)2 * 1024 * 1024 * 1024; // 2GB
const uint64_t MAX_REST_WORKERS = 10'000;

Config& Config::parse(int argc, char** argv) {
ovms::CLIParser p;
ovms::CLIParser parser;
ovms::ServerSettingsImpl serverSettings;
ovms::ModelsSettingsImpl modelsSettings;
p.parse(argc, argv);
p.prepare(&serverSettings, &modelsSettings);
auto successOrExit = parser.parse(argc, argv);
// Check for error in parsing
if (std::holds_alternative<std::pair<int, std::string>>(successOrExit)) {
auto printAndExit = std::get<std::pair<int, std::string>>(successOrExit);
if (printAndExit.first > 0) {
std::cerr << printAndExit.second;
} else {
std::cout << printAndExit.second;
}
exit(printAndExit.first);
}
parser.prepare(&serverSettings, &modelsSettings);
if (!this->parse(&serverSettings, &modelsSettings))
exit(OVMS_EX_USAGE);
return *this;
Expand Down
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ int main(int argc, char** argv) {
return server.start(argc, argv);
}
#elif _WIN32
#pragma warning(push)
#pragma warning(disable : 6553)
#include "main_windows.hpp"
#pragma warning(pop)

int main(int argc, char** argv) {
return ovms_service::main_windows(argc, argv);
Expand Down
Loading