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

Commit 80da991

Browse files
committed
chore: cleanup httplib
update update update update update update
1 parent 0ffe3d4 commit 80da991

30 files changed

+305
-369
lines changed

engine/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ add_subdirectory(cli)
6767
find_package(jsoncpp CONFIG REQUIRED)
6868
find_package(Drogon CONFIG REQUIRED)
6969
find_package(yaml-cpp CONFIG REQUIRED)
70-
find_package(httplib CONFIG REQUIRED)
7170
find_package(unofficial-minizip CONFIG REQUIRED)
7271
find_package(LibArchive REQUIRED)
7372
find_package(CURL REQUIRED)
@@ -143,7 +142,6 @@ add_executable(${TARGET_NAME} main.cc
143142

144143
target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
145144

146-
target_link_libraries(${TARGET_NAME} PRIVATE httplib::httplib)
147145
target_link_libraries(${TARGET_NAME} PRIVATE unofficial::minizip::minizip)
148146
target_link_libraries(${TARGET_NAME} PRIVATE LibArchive::LibArchive)
149147
target_link_libraries(${TARGET_NAME} PRIVATE CURL::libcurl)

engine/cli/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}")
5757

5858
find_package(jsoncpp CONFIG REQUIRED)
5959
find_package(yaml-cpp CONFIG REQUIRED)
60-
find_package(httplib CONFIG REQUIRED)
6160
find_package(CLI11 CONFIG REQUIRED)
6261
find_package(unofficial-minizip CONFIG REQUIRED)
6362
find_package(LibArchive REQUIRED)
@@ -83,7 +82,6 @@ add_executable(${TARGET_NAME} main.cc
8382
${CMAKE_CURRENT_SOURCE_DIR}/utils/download_progress.cc
8483
)
8584

86-
target_link_libraries(${TARGET_NAME} PRIVATE httplib::httplib)
8785
target_link_libraries(${TARGET_NAME} PRIVATE CLI11::CLI11)
8886
target_link_libraries(${TARGET_NAME} PRIVATE unofficial::minizip::minizip)
8987
target_link_libraries(${TARGET_NAME} PRIVATE LibArchive::LibArchive)

engine/cli/command_line_parser.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ void CommandLineParser::SetupCommonCommands() {
149149
return;
150150
}
151151
try {
152-
commands::ModelPullCmd(download_service_)
153-
.Exec(cml_data_.config.apiServerHost,
154-
std::stoi(cml_data_.config.apiServerPort), cml_data_.model_id);
152+
commands::ModelPullCmd().Exec(cml_data_.config.apiServerHost,
153+
std::stoi(cml_data_.config.apiServerPort),
154+
cml_data_.model_id);
155155
} catch (const std::exception& e) {
156156
CLI_LOG(e.what());
157157
}

engine/cli/commands/chat_completion_cmd.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ void ChatCompletionCmd::Exec(const std::string& host, int port,
8080
// Only check if llamacpp engine
8181
if ((mc.engine.find(kLlamaEngine) != std::string::npos ||
8282
mc.engine.find(kLlamaRepo) != std::string::npos) &&
83-
!commands::ModelStatusCmd(model_service_)
84-
.IsLoaded(host, port, model_handle)) {
83+
!commands::ModelStatusCmd().IsLoaded(host, port, model_handle)) {
8584
CLI_LOG("Model is not loaded yet!");
8685
return;
8786
}

engine/cli/commands/engine_install_cmd.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ bool EngineInstallCmd::Exec(const std::string& engine,
183183
return false;
184184
}
185185

186-
CLI_LOG("Validating download items, please wait..")
187-
188186
if (!dp_res.get())
189187
return false;
190188

engine/cli/commands/hardware_activate_cmd.cc

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ bool HardwareActivateCmd::Exec(
3636
}
3737
}
3838

39-
// TODO(sang) should use curl but it does not work (?)
4039
Json::Value body;
4140
Json::Value gpus_json = Json::arrayValue;
4241
std::vector<int> gpus;
@@ -51,36 +50,30 @@ bool HardwareActivateCmd::Exec(
5150
body["gpus"] = gpus_json;
5251
auto data_str = body.toStyledString();
5352

54-
httplib::Client cli(host + ":" + std::to_string(port));
53+
auto url = url_parser::Url{
54+
.protocol = "http",
55+
.host = host + ":" + std::to_string(port),
56+
.pathParams = {"v1", "hardware", "activate"},
57+
};
5558

56-
auto res = cli.Post("/v1/hardware/activate", httplib::Headers(),
57-
data_str.data(), data_str.size(), "application/json");
58-
if (res) {
59-
if (res->status == httplib::StatusCode::OK_200) {
60-
auto root = json_helper::ParseJsonString(res->body);
61-
if (!root["warning"].isNull()) {
62-
CLI_LOG(root["warning"].asString());
63-
}
64-
if(body["gpus"].empty()) {
65-
CLI_LOG("Deactivated all GPUs!");
66-
} else {
67-
std::string gpus_str;
68-
for(auto i: gpus) {
69-
gpus_str += " " + std::to_string(i);
70-
}
71-
CLI_LOG("Activated GPUs:" << gpus_str);
72-
}
73-
return true;
74-
} else {
75-
auto root = json_helper::ParseJsonString(res->body);
76-
CLI_LOG(root["message"].asString());
77-
return false;
78-
}
79-
} else {
80-
auto err = res.error();
81-
CTL_ERR("HTTP error: " << httplib::to_string(err));
59+
auto res = curl_utils::SimplePostJson(url.ToFullPath(), data_str);
60+
if (res.has_error()) {
61+
auto root = json_helper::ParseJsonString(res.error());
62+
CLI_LOG(root["message"].asString());
8263
return false;
8364
}
65+
if (!res.value()["warning"].isNull()) {
66+
CLI_LOG(res.value()["warning"].asString());
67+
}
68+
if (body["gpus"].empty()) {
69+
CLI_LOG("Deactivated all GPUs!");
70+
} else {
71+
std::string gpus_str;
72+
for (auto i : gpus) {
73+
gpus_str += " " + std::to_string(i);
74+
}
75+
CLI_LOG("Activated GPUs:" << gpus_str);
76+
}
8477
return true;
8578
}
86-
} // namespace commands
79+
} // namespace commands
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
2+
23
#include <string>
34
#include <unordered_map>
4-
#include "common/hardware_config.h"
55

66
namespace commands {
77
class HardwareActivateCmd {
88
public:
99
bool Exec(const std::string& host, int port,
1010
const std::unordered_map<std::string, std::string>& options);
1111
};
12-
} // namespace commands
12+
} // namespace commands

engine/cli/commands/hardware_list_cmd.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
#include "hardware_list_cmd.h"
2-
32
#include <json/reader.h>
43
#include <json/value.h>
54
#include <iostream>
6-
75
#include <vector>
8-
#include "httplib.h"
96
#include "server_start_cmd.h"
7+
#include "services/hardware_service.h"
108
#include "utils/curl_utils.h"
11-
#include "utils/hardware/cpu_info.h"
12-
#include "utils/hardware/gpu_info.h"
13-
#include "utils/hardware/os_info.h"
14-
#include "utils/hardware/power_info.h"
15-
#include "utils/hardware/ram_info.h"
16-
#include "utils/hardware/storage_info.h"
179
#include "utils/logging_utils.h"
18-
#include "utils/string_utils.h"
1910
// clang-format off
2011
#include <tabulate/table.hpp>
2112
// clang-format on
@@ -186,4 +177,4 @@ bool HardwareListCmd::Exec(const std::string& host, int port,
186177

187178
return true;
188179
}
189-
} // namespace commands
180+
} // namespace commands
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "model_del_cmd.h"
2-
#include "httplib.h"
32
#include "server_start_cmd.h"
3+
#include "utils/curl_utils.h"
44
#include "utils/logging_utils.h"
5+
#include "utils/url_parser.h"
56

67
namespace commands {
78

@@ -16,18 +17,17 @@ void ModelDelCmd::Exec(const std::string& host, int port,
1617
}
1718
}
1819

19-
// Call API to delete model
20-
httplib::Client cli(host + ":" + std::to_string(port));
21-
auto res = cli.Delete("/v1/models/" + model_handle);
22-
if (res) {
23-
if (res->status == httplib::StatusCode::OK_200) {
24-
CLI_LOG("Model " + model_handle + " deleted successfully");
25-
} else {
26-
CTL_ERR("Model failed to delete with status code: " << res->status);
27-
}
28-
} else {
29-
auto err = res.error();
30-
CTL_ERR("HTTP error: " << httplib::to_string(err));
20+
auto url = url_parser::Url{
21+
.protocol = "http",
22+
.host = host + ":" + std::to_string(port),
23+
.pathParams = {"v1", "models", model_handle},
24+
};
25+
26+
auto res = curl_utils::SimpleDeleteJson(url.ToFullPath());
27+
if (res.has_error()) {
28+
CLI_LOG("Failed to delete model: " << res.error());
29+
return;
3130
}
31+
CLI_LOG("Model " + model_handle + " deleted successfully");
3232
}
3333
} // namespace commands
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "model_get_cmd.h"
2-
#include "httplib.h"
32
#include "server_start_cmd.h"
3+
#include "utils/curl_utils.h"
44
#include "utils/json_helper.h"
55
#include "utils/logging_utils.h"
6+
#include "utils/url_parser.h"
67

78
namespace commands {
89

@@ -17,20 +18,19 @@ void ModelGetCmd::Exec(const std::string& host, int port,
1718
}
1819
}
1920

20-
// Call API to delete model
21-
httplib::Client cli(host + ":" + std::to_string(port));
22-
auto res = cli.Get("/v1/models/" + model_handle);
23-
if (res) {
24-
if (res->status == httplib::StatusCode::OK_200) {
25-
CLI_LOG(res->body);
26-
} else {
27-
auto root = json_helper::ParseJsonString(res->body);
28-
CLI_LOG(root["message"].asString());
29-
}
30-
} else {
31-
auto err = res.error();
32-
CTL_ERR("HTTP error: " << httplib::to_string(err));
21+
auto url = url_parser::Url{
22+
.protocol = "http",
23+
.host = host + ":" + std::to_string(port),
24+
.pathParams = {"v1", "models", model_handle},
25+
};
26+
27+
auto res = curl_utils::SimpleGetJson(url.ToFullPath());
28+
if (res.has_error()) {
29+
auto root = json_helper::ParseJsonString(res.error());
30+
CLI_LOG(root["message"].asString());
31+
return;
3332
}
34-
}
3533

34+
CLI_LOG(res.value().toStyledString());
35+
}
3636
} // namespace commands

0 commit comments

Comments
 (0)