Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 0776c59

Browse files
committed
fix: add more parameters to config command
1 parent 3ff301a commit 0776c59

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

engine/cli/command_line_parser.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ void CommandLineParser::SetupConfigsCommands() {
437437

438438
auto is_empty = true;
439439
for (const auto& [key, value] : config_update_opts_) {
440-
if (!value.empty()) {
440+
if (!value.empty() || CONFIGURATIONS.at(key).allow_empty) {
441441
is_empty = false;
442442
break;
443443
}
@@ -657,6 +657,7 @@ void CommandLineParser::SetupSystemCommands() {
657657
auto start_cmd = app_.add_subcommand("start", "Start the API server");
658658
start_cmd->group(kSystemGroup);
659659
cml_data_.port = std::stoi(cml_data_.config.apiServerPort);
660+
start_cmd->add_option("--host", cml_data_.server_host, "Server host");
660661
start_cmd->add_option("-p, --port", cml_data_.port, "Server port to listen");
661662
start_cmd->add_option("--loglevel", cml_data_.log_level,
662663
"Set up log level for server, accepted TRACE, DEBUG, "
@@ -671,10 +672,16 @@ void CommandLineParser::SetupSystemCommands() {
671672
start_cmd->callback([this] {
672673
if (std::exchange(executed_, true))
673674
return;
674-
if (cml_data_.port != stoi(cml_data_.config.apiServerPort)) {
675-
CTL_INF("apiServerPort changed from " << cml_data_.config.apiServerPort
676-
<< " to " << cml_data_.port);
675+
if (cml_data_.port != stoi(cml_data_.config.apiServerPort) ||
676+
(!cml_data_.server_host.empty() &&
677+
cml_data_.server_host != cml_data_.config.apiServerHost)) {
678+
CTL_INF("API server host:port changed from "
679+
<< cml_data_.config.apiServerHost << ":"
680+
<< cml_data_.config.apiServerPort << " to "
681+
<< cml_data_.server_host << ":" << cml_data_.port);
677682
auto config_path = file_manager_utils::GetConfigurationPath();
683+
if (!cml_data_.server_host.empty())
684+
cml_data_.config.apiServerHost = cml_data_.server_host;
678685
cml_data_.config.apiServerPort = std::to_string(cml_data_.port);
679686
auto result =
680687
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(

engine/cli/command_line_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CommandLineParser {
7171

7272
bool show_menu = false;
7373

74+
std::string server_host;
7475
int port;
7576
config_yaml_utils::CortexConfig config;
7677
std::unordered_map<std::string, std::string> model_update_options;

engine/cli/commands/config_upd_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void commands::ConfigUpdCmd::Exec(
5656

5757
auto non_null_opts = std::unordered_map<std::string, std::string>();
5858
for (const auto& [key, value] : options) {
59-
if (value.empty()) {
59+
if (value.empty() && !CONFIGURATIONS.at(key).allow_empty) {
6060
continue;
6161
}
6262
non_null_opts[key] = value;

engine/common/api_server_configuration.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ static const std::unordered_map<std::string, ApiConfigurationMetadata>
9797
.accept_value = "string",
9898
.default_value = "",
9999
.allow_empty = true}},
100+
{"github_token", ApiConfigurationMetadata{.name = "github_token",
101+
.desc = "Github token",
102+
.group = "Token",
103+
.accept_value = "string",
104+
.default_value = "",
105+
.allow_empty = true}},
100106
};
101107

102108
class ApiServerConfiguration {
@@ -107,7 +113,7 @@ class ApiServerConfiguration {
107113
const std::string& proxy_url = "", const std::string& proxy_username = "",
108114
const std::string& proxy_password = "", const std::string& no_proxy = "",
109115
bool verify_peer_ssl = true, bool verify_host_ssl = true,
110-
const std::string& hf_token = "")
116+
const std::string& hf_token = "", const std::string& gh_token = "")
111117
: cors{cors},
112118
allowed_origins{allowed_origins},
113119
verify_proxy_ssl{verify_proxy_ssl},
@@ -118,7 +124,8 @@ class ApiServerConfiguration {
118124
no_proxy{no_proxy},
119125
verify_peer_ssl{verify_peer_ssl},
120126
verify_host_ssl{verify_host_ssl},
121-
hf_token{hf_token} {}
127+
hf_token{hf_token},
128+
gh_token{gh_token} {}
122129

123130
// cors
124131
bool cors{true};
@@ -138,6 +145,7 @@ class ApiServerConfiguration {
138145

139146
// token
140147
std::string hf_token{""};
148+
std::string gh_token{""};
141149

142150
Json::Value ToJson() const {
143151
Json::Value root;
@@ -155,6 +163,7 @@ class ApiServerConfiguration {
155163
root["verify_peer_ssl"] = verify_peer_ssl;
156164
root["verify_host_ssl"] = verify_host_ssl;
157165
root["huggingface_token"] = hf_token;
166+
root["github_token"] = gh_token;
158167

159168
return root;
160169
}
@@ -247,6 +256,15 @@ class ApiServerConfiguration {
247256
return true;
248257
}},
249258

259+
{"github_token",
260+
[this](const Json::Value& value) -> bool {
261+
if (!value.isString()) {
262+
return false;
263+
}
264+
gh_token = value.asString();
265+
return true;
266+
}},
267+
250268
{"cors",
251269
[this](const Json::Value& value) -> bool {
252270
if (!value.isBool()) {

engine/services/config_service.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ cpp::result<ApiServerConfiguration, std::string>
66
ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
77
auto config = file_manager_utils::GetCortexConfig();
88
ApiServerConfiguration api_server_config{
9-
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
10-
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
11-
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
12-
config.verifyHostSsl, config.huggingFaceToken};
9+
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
10+
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
11+
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
12+
config.verifyHostSsl, config.huggingFaceToken, config.gitHubToken};
1313

1414
std::vector<std::string> updated_fields;
1515
std::vector<std::string> invalid_fields;
@@ -36,6 +36,7 @@ ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
3636
config.verifyHostSsl = api_server_config.verify_host_ssl;
3737

3838
config.huggingFaceToken = api_server_config.hf_token;
39+
config.gitHubToken = api_server_config.gh_token;
3940

4041
auto result = file_manager_utils::UpdateCortexConfig(config);
4142
return api_server_config;
@@ -45,8 +46,8 @@ cpp::result<ApiServerConfiguration, std::string>
4546
ConfigService::GetApiServerConfiguration() {
4647
auto config = file_manager_utils::GetCortexConfig();
4748
return ApiServerConfiguration{
48-
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
49-
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
50-
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
51-
config.verifyHostSsl, config.huggingFaceToken};
49+
config.enableCors, config.allowedOrigins, config.verifyProxySsl,
50+
config.verifyProxyHostSsl, config.proxyUrl, config.proxyUsername,
51+
config.proxyPassword, config.noProxy, config.verifyPeerSsl,
52+
config.verifyHostSsl, config.huggingFaceToken, config.gitHubToken};
5253
}

0 commit comments

Comments
 (0)