forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_get_cmd.cc
More file actions
37 lines (32 loc) · 1017 Bytes
/
model_get_cmd.cc
File metadata and controls
37 lines (32 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "model_get_cmd.h"
#include "server_start_cmd.h"
#include "utils/curl_utils.h"
#include "utils/json_helper.h"
#include "utils/logging_utils.h"
#include "utils/url_parser.h"
namespace commands {
void ModelGetCmd::Exec(const std::string& host, int port,
const std::string& model_handle) {
// Start server if server is not started yet
if (!commands::IsServerAlive(host, port)) {
CLI_LOG("Starting server ...");
commands::ServerStartCmd ssc;
if (!ssc.Exec(host, port)) {
return;
}
}
auto url = url_parser::Url{
/* .protocol = */ "http",
/* .host = */ host + ":" + std::to_string(port),
/* .pathParams = */ {"v1", "models", model_handle},
/* .queries = */ {},
};
auto res = curl_utils::SimpleGetJson(url.ToFullPath());
if (res.has_error()) {
auto root = json_helper::ParseJsonString(res.error());
CLI_LOG(root["message"].asString());
return;
}
CLI_LOG(res.value().toStyledString());
}
} // namespace commands