1+ #include " start_model_cmd.h"
2+ #include " httplib.h"
3+ #include " nlohmann/json.hpp"
4+ #include " trantor/utils/Logger.h"
5+
6+ namespace commands {
7+ StartModelCmd::StartModelCmd (std::string host, int port,
8+ const config::ModelConfig& mc)
9+ : host_(std::move(host)), port_(port), mc_(mc) {}
10+
11+ void StartModelCmd::Exec () {
12+ httplib::Client cli (host_ + " :" + std::to_string (port_));
13+ nlohmann::json json_data;
14+ if (mc_.files .size () > 0 ) {
15+ // TODO(sang) support multiple files
16+ json_data[" model_path" ] = mc_.files [0 ];
17+ } else {
18+ LOG_WARN << " model_path is empty" ;
19+ return ;
20+ }
21+ json_data[" model" ] = mc_.name ;
22+ json_data[" system_prompt" ] = mc_.system_template ;
23+ json_data[" user_prompt" ] = mc_.user_template ;
24+ json_data[" ai_prompt" ] = mc_.ai_template ;
25+ json_data[" ctx_len" ] = mc_.ctx_len ;
26+ json_data[" stop" ] = mc_.stop ;
27+ json_data[" engine" ] = mc_.engine ;
28+
29+ auto data_str = json_data.dump ();
30+
31+ auto res = cli.Post (" /inferences/server/loadmodel" , httplib::Headers (),
32+ data_str.data (), data_str.size (), " application/json" );
33+ if (res) {
34+ if (res->status == httplib::StatusCode::OK_200) {
35+ LOG_INFO << res->body ;
36+ }
37+ } else {
38+ auto err = res.error ();
39+ LOG_WARN << " HTTP error: " << httplib::to_string (err);
40+ }
41+ }
42+
43+ }; // namespace commands
0 commit comments