@@ -138,4 +138,171 @@ bool ServerStartCmd::Exec(const std::string& host, int port,
138138#endif
139139 return true ;
140140}
141+
142+ bool ServerStartCmd::Exec (
143+ const std::optional<std::string>& log_level,
144+ const std::unordered_map<std::string, std::string>& options,
145+ CortexConfig& data) {
146+ for (const auto & [key, value] : options) {
147+ if (!value.empty ()) {
148+ UpdateConfig (data, key, value);
149+ }
150+ }
151+
152+ auto config_path = file_manager_utils::GetConfigurationPath ();
153+ auto result =
154+ config_yaml_utils::CortexConfigMgr::GetInstance ().DumpYamlConfig (
155+ data, config_path.string ());
156+ if (result.has_error ()) {
157+ CTL_WRN (" Error update " << config_path.string () << result.error ());
158+ }
159+ return Exec (data.apiServerHost , std::stoi (data.apiServerPort ), log_level);
160+ }
161+
162+ void ServerStartCmd::UpdateConfig (CortexConfig& data, const std::string& key,
163+ const std::string& value) {
164+ static const std::unordered_map<
165+ std::string, std::function<void (CortexConfig&, const std::string&,
166+ const std::string&)>>
167+ updaters = {
168+ {" logspath" ,
169+ [](CortexConfig& data, const std::string&, const std::string& v) {
170+ data.logFolderPath = v;
171+ }},
172+ {" logsllama" ,
173+ [](CortexConfig& data, const std::string&, const std::string& v) {
174+ data.logLlamaCppPath = v;
175+ }},
176+ {" logsonnx" ,
177+ [](CortexConfig& data, const std::string&, const std::string& v) {
178+ data.logOnnxPath = v;
179+ }},
180+ {" loglines" ,
181+ [this ](CortexConfig& data, const std::string& k,
182+ const std::string& v) {
183+ UpdateNumericField (k, v, [&data](float f) {
184+ data.maxLogLines = static_cast <int >(f);
185+ });
186+ }},
187+ {" host" ,
188+ [](CortexConfig& data, const std::string&, const std::string& v) {
189+ data.apiServerHost = v;
190+ }},
191+ {" port" ,
192+ [](CortexConfig& data, const std::string& k, const std::string& v) {
193+ data.apiServerPort = v;
194+ }},
195+ {" hf-token" ,
196+ [](CortexConfig& data, const std::string&, const std::string& v) {
197+ data.huggingFaceToken = v;
198+ }},
199+ {" gh-agent" ,
200+ [](CortexConfig& data, const std::string&, const std::string& v) {
201+ data.gitHubUserAgent = v;
202+ }},
203+ {" gh-token" ,
204+ [](CortexConfig& data, const std::string&, const std::string& v) {
205+ data.gitHubToken = v;
206+ }},
207+ {" cors" ,
208+ [this ](CortexConfig& data, const std::string& k,
209+ const std::string& v) {
210+ UpdateBooleanField (k, v, [&data](bool b) { data.enableCors = b; });
211+ }},
212+ {" origins" ,
213+ [this ](CortexConfig& data, const std::string& k,
214+ const std::string& v) {
215+ UpdateVectorField (k, v,
216+ [&data](const std::vector<std::string>& orgs) {
217+ data.allowedOrigins = orgs;
218+ });
219+ }},
220+ {" proxy-url" ,
221+ [](CortexConfig& data, const std::string&, const std::string& v) {
222+ data.proxyUrl = v;
223+ }},
224+ {" verify-proxy" ,
225+ [this ](CortexConfig& data, const std::string& k,
226+ const std::string& v) {
227+ UpdateBooleanField (k, v,
228+ [&data](bool b) { data.verifyProxySsl = b; });
229+ }},
230+ {" verify-proxy-host" ,
231+ [this ](CortexConfig& data, const std::string& k,
232+ const std::string& v) {
233+ UpdateBooleanField (
234+ k, v, [&data](bool b) { data.verifyProxyHostSsl = b; });
235+ }},
236+ {" proxy-username" ,
237+ [](CortexConfig& data, const std::string&, const std::string& v) {
238+ data.proxyUsername = v;
239+ }},
240+ {" proxy-password" ,
241+ [](CortexConfig& data, const std::string&, const std::string& v) {
242+ data.proxyPassword = v;
243+ }},
244+ {" no-proxy" ,
245+ [](CortexConfig& data, const std::string&, const std::string& v) {
246+ data.noProxy = v;
247+ }},
248+ {" verify-ssl-peer" ,
249+ [this ](CortexConfig& data, const std::string& k,
250+ const std::string& v) {
251+ UpdateBooleanField (k, v,
252+ [&data](bool b) { data.verifyPeerSsl = b; });
253+ }},
254+ {" verify-ssl-host" ,
255+ [this ](CortexConfig& data, const std::string& k,
256+ const std::string& v) {
257+ UpdateBooleanField (k, v,
258+ [&data](bool b) { data.verifyHostSsl = b; });
259+ }},
260+ {" ssl-cert-path" ,
261+ [](CortexConfig& data, const std::string&, const std::string& v) {
262+ data.sslCertPath = v;
263+ }},
264+ {" ssl-key-path" ,
265+ [](CortexConfig& data, const std::string&, const std::string& v) {
266+ data.sslKeyPath = v;
267+ }},
268+ };
269+
270+ if (auto it = updaters.find (key); it != updaters.end ()) {
271+ it->second (data, key, value);
272+ CTL_INF (" Updated " << key << " to: " << value);
273+ } else {
274+ CTL_WRN (" Warning: Unknown configuration key '" << key << " ' ignored." );
275+ }
276+ }
277+
278+ void ServerStartCmd::UpdateVectorField (
279+ const std::string& key, const std::string& value,
280+ std::function<void (const std::vector<std::string>&)> setter) {
281+ std::vector<std::string> tokens;
282+ std::istringstream iss (value);
283+ std::string token;
284+ while (std::getline (iss, token, ' ,' )) {
285+ tokens.push_back (token);
286+ }
287+ setter (tokens);
288+ }
289+
290+ void ServerStartCmd::UpdateNumericField (const std::string& key,
291+ const std::string& value,
292+ std::function<void (float )> setter) {
293+ try {
294+ float numeric_val = std::stof (value);
295+ setter (numeric_val);
296+ } catch (const std::exception& e) {
297+ CLI_LOG (" Failed to parse numeric value for " << key << " : " << e.what ());
298+ }
299+ }
300+
301+ void ServerStartCmd::UpdateBooleanField (const std::string& key,
302+ const std::string& value,
303+ std::function<void (bool )> setter) {
304+ bool bool_value = (value == " true" || value == " 1" );
305+ setter (bool_value);
306+ }
307+
141308}; // namespace commands
0 commit comments