forked from janhq/cortex.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathps_cmd.cc
More file actions
67 lines (60 loc) · 2.05 KB
/
ps_cmd.cc
File metadata and controls
67 lines (60 loc) · 2.05 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "ps_cmd.h"
#include <string>
#include <tabulate/table.hpp>
#include "utils/curl_utils.h"
#include "utils/engine_constants.h"
#include "utils/format_utils.h"
#include "utils/logging_utils.h"
#include "utils/string_utils.h"
#include "utils/url_parser.h"
namespace commands {
void PsCmd::Exec(const std::string& host, int port) {
auto url = url_parser::Url{
/* .protocol = */ "http",
/* .host = */ host + ":" + std::to_string(port),
/* .pathParams = */ {"inferences", "server", "models"},
/* .queries = */ {},
};
auto res = curl_utils::SimpleGetJson(url.ToFullPath());
if (res.has_error()) {
CLI_LOG("No models loaded!");
return;
}
std::vector<ModelLoadedStatus> model_status_list;
try {
for (const auto& item : res.value()["data"]) {
ModelLoadedStatus model_status;
// TODO(sang) hardcode for now
model_status.engine = item["engine"].isNull()
? kLlamaEngine : item["engine"].asString();
model_status.model = item["id"].asString();
model_status.ram = item["ram"].asUInt64();
model_status.start_time = item["start_time"].asUInt64();
model_status.vram = item["vram"].asUInt64();
model_status_list.push_back(model_status);
}
} catch (const std::exception& e) {
CLI_LOG("Fail to get list model information: " + std::string(e.what()));
}
PrintModelStatusList(model_status_list);
}
void PsCmd::PrintModelStatusList(
const std::vector<ModelLoadedStatus>& model_status_list) const {
if (model_status_list.empty()) {
CLI_LOG("No models loaded!");
return;
}
tabulate::Table table;
table.add_row({"Model", "Engine", "RAM", "VRAM", "Up time"});
for (const auto& model_status : model_status_list) {
table.add_row({
model_status.model,
model_status.engine,
format_utils::BytesToHumanReadable(model_status.ram),
format_utils::BytesToHumanReadable(model_status.vram),
string_utils::FormatTimeElapsed(model_status.start_time),
});
}
std::cout << table << std::endl;
}
}; // namespace commands