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

Commit 4a4f2f7

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

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

engine/common/api_server_configuration.h

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ static const std::unordered_map<std::string, ApiConfigurationMetadata>
9797
.accept_value = "string",
9898
.default_value = "",
9999
.allow_empty = true}},
100+
{"api_server_host", ApiConfigurationMetadata{.name = "api_server_host",
101+
.desc = "API server host",
102+
.group = "Server setup",
103+
.accept_value = "string",
104+
.default_value = ""}},
105+
{"api_server_port", ApiConfigurationMetadata{.name = "api_server_port",
106+
.desc = "API server port",
107+
.group = "Server setup",
108+
.accept_value = "integer",
109+
.default_value = ""}},
100110
};
101111

102112
class ApiServerConfiguration {
@@ -107,7 +117,8 @@ class ApiServerConfiguration {
107117
const std::string& proxy_url = "", const std::string& proxy_username = "",
108118
const std::string& proxy_password = "", const std::string& no_proxy = "",
109119
bool verify_peer_ssl = true, bool verify_host_ssl = true,
110-
const std::string& hf_token = "")
120+
const std::string& hf_token = "", const std::string& server_host = "",
121+
int server_port = 39281)
111122
: cors{cors},
112123
allowed_origins{allowed_origins},
113124
verify_proxy_ssl{verify_proxy_ssl},
@@ -118,7 +129,9 @@ class ApiServerConfiguration {
118129
no_proxy{no_proxy},
119130
verify_peer_ssl{verify_peer_ssl},
120131
verify_host_ssl{verify_host_ssl},
121-
hf_token{hf_token} {}
132+
hf_token{hf_token},
133+
server_host{server_host},
134+
server_port{server_port} {}
122135

123136
// cors
124137
bool cors{true};
@@ -139,6 +152,9 @@ class ApiServerConfiguration {
139152
// token
140153
std::string hf_token{""};
141154

155+
std::string server_host{"127.0.0.1"};
156+
int server_port{39281};
157+
142158
Json::Value ToJson() const {
143159
Json::Value root;
144160
root["cors"] = cors;
@@ -155,7 +171,8 @@ class ApiServerConfiguration {
155171
root["verify_peer_ssl"] = verify_peer_ssl;
156172
root["verify_host_ssl"] = verify_host_ssl;
157173
root["huggingface_token"] = hf_token;
158-
174+
root["server_host"] = server_host;
175+
root["server_port"] = server_port;
159176
return root;
160177
}
161178

@@ -246,7 +263,22 @@ class ApiServerConfiguration {
246263
hf_token = value.asString();
247264
return true;
248265
}},
249-
266+
{"server_host",
267+
[this](const Json::Value& value) -> bool {
268+
if (!value.isString()) {
269+
return false;
270+
}
271+
server_host = value.asString();
272+
return true;
273+
}},
274+
{"server_port",
275+
[this](const Json::Value& value) -> bool {
276+
if (!value.isNumeric()) {
277+
return false;
278+
}
279+
server_port = value.asInt();
280+
return true;
281+
}},
250282
{"cors",
251283
[this](const Json::Value& value) -> bool {
252284
if (!value.isBool()) {

engine/services/config_service.cc

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
cpp::result<ApiServerConfiguration, std::string>
66
ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
77
auto config = file_manager_utils::GetCortexConfig();
8-
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};
8+
ApiServerConfiguration api_server_config{config.enableCors,
9+
config.allowedOrigins,
10+
config.verifyProxySsl,
11+
config.verifyProxyHostSsl,
12+
config.proxyUrl,
13+
config.proxyUsername,
14+
config.proxyPassword,
15+
config.noProxy,
16+
config.verifyPeerSsl,
17+
config.verifyHostSsl,
18+
config.huggingFaceToken,
19+
config.apiServerHost,
20+
std::stoi(config.apiServerPort)};
1321

1422
std::vector<std::string> updated_fields;
1523
std::vector<std::string> invalid_fields;
@@ -36,6 +44,8 @@ ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
3644
config.verifyHostSsl = api_server_config.verify_host_ssl;
3745

3846
config.huggingFaceToken = api_server_config.hf_token;
47+
config.apiServerHost = api_server_config.server_host;
48+
config.apiServerPort = std::to_string(api_server_config.server_port);
3949

4050
auto result = file_manager_utils::UpdateCortexConfig(config);
4151
return api_server_config;
@@ -44,9 +54,17 @@ ConfigService::UpdateApiServerConfiguration(const Json::Value& json) {
4454
cpp::result<ApiServerConfiguration, std::string>
4555
ConfigService::GetApiServerConfiguration() {
4656
auto config = file_manager_utils::GetCortexConfig();
47-
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};
57+
return ApiServerConfiguration{config.enableCors,
58+
config.allowedOrigins,
59+
config.verifyProxySsl,
60+
config.verifyProxyHostSsl,
61+
config.proxyUrl,
62+
config.proxyUsername,
63+
config.proxyPassword,
64+
config.noProxy,
65+
config.verifyPeerSsl,
66+
config.verifyHostSsl,
67+
config.huggingFaceToken,
68+
config.apiServerHost,
69+
std::stoi(config.apiServerPort)};
5270
}

0 commit comments

Comments
 (0)