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

Commit 6980a95

Browse files
committed
fix: better output for cortex cli
1 parent 670a477 commit 6980a95

21 files changed

+118
-65
lines changed

engine/commands/chat_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "httplib.h"
33

44
#include "trantor/utils/Logger.h"
5+
#include "utils/logging_utils.h"
56

67
namespace commands {
78
namespace {
@@ -48,12 +49,12 @@ void ChatCmd::Exec(std::string msg) {
4849
data_str.data(), data_str.size(), "application/json");
4950
if (res) {
5051
if (res->status != httplib::StatusCode::OK_200) {
51-
LOG_INFO << res->body;
52+
CTLOG_ERROR(res->body);
5253
return;
5354
}
5455
} else {
5556
auto err = res.error();
56-
LOG_WARN << "HTTP error: " << httplib::to_string(err);
57+
CTLOG_ERROR("HTTP error: " << httplib::to_string(err));
5758
return;
5859
}
5960
}

engine/commands/cmd_info.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "cmd_info.h"
22
#include <vector>
33
#include "trantor/utils/Logger.h"
4+
#include "utils/logging_utils.h"
45

56
namespace commands {
67
namespace {
@@ -33,7 +34,7 @@ void CmdInfo::Parse(std::string model_id) {
3334
} else {
3435
auto res = split(model_id, kDelimiter);
3536
if (res.size() != 2) {
36-
LOG_ERROR << "model_id does not valid";
37+
CTLOG_ERROR("<model_id> does not valid");
3738
return;
3839
} else {
3940
model_name = std::move(res[0]);
@@ -45,7 +46,7 @@ void CmdInfo::Parse(std::string model_id) {
4546
} else if (branch.find("gguf") != std::string::npos) {
4647
engine_name = "cortex.llamacpp";
4748
} else {
48-
LOG_ERROR << "Not a valid branch model_name " << branch;
49+
CTLOG_ERROR("Not a valid branch model_name " << branch);
4950
}
5051
}
5152
}

engine/commands/engine_init_cmd.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool EngineInitCmd::Exec() const {
2929
<< system_info.arch;
3030
return false;
3131
}
32-
LOG_INFO << "OS: " << system_info.os << ", Arch: " << system_info.arch;
32+
CTLOG_INFO("OS: " << system_info.os << ", Arch: " << system_info.arch);
3333

3434
// check if engine is supported
3535
if (std::find(supportedEngines_.begin(), supportedEngines_.end(),
@@ -43,7 +43,7 @@ bool EngineInitCmd::Exec() const {
4343
std::ostringstream engineReleasePath;
4444
engineReleasePath << "/repos/janhq/" << engineName_ << "/releases/"
4545
<< version;
46-
LOG_INFO << "Engine release path: " << gitHubHost << engineReleasePath.str();
46+
CTLOG_INFO("Engine release path: " << gitHubHost << engineReleasePath.str());
4747
using namespace nlohmann;
4848

4949
httplib::Client cli(gitHubHost);
@@ -61,8 +61,8 @@ bool EngineInitCmd::Exec() const {
6161
}
6262

6363
auto cuda_version = system_info_utils::GetCudaVersion();
64-
LOG_INFO << "engineName_: " << engineName_;
65-
LOG_INFO << "CUDA version: " << cuda_version;
64+
CTLOG_INFO("engineName_: " << engineName_);
65+
CTLOG_INFO("CUDA version: " << cuda_version);
6666
std::string matched_variant = "";
6767
if (engineName_ == "cortex.tensorrt-llm") {
6868
matched_variant = engine_matcher_utils::ValidateTensorrtLlm(
@@ -76,7 +76,7 @@ bool EngineInitCmd::Exec() const {
7676
variants, system_info.os, system_info.arch, suitable_avx,
7777
cuda_version);
7878
}
79-
LOG_INFO << "Matched variant: " << matched_variant;
79+
CTLOG_INFO("Matched variant: " << matched_variant);
8080
if (matched_variant.empty()) {
8181
LOG_ERROR << "No variant found for " << os_arch;
8282
return false;
@@ -91,7 +91,7 @@ bool EngineInitCmd::Exec() const {
9191
std::string path = full_url.substr(host.length());
9292

9393
auto fileName = asset["name"].get<std::string>();
94-
LOG_INFO << "URL: " << full_url;
94+
CTLOG_INFO("URL: " << full_url);
9595

9696
auto downloadTask = DownloadTask{.id = engineName_,
9797
.type = DownloadType::Engine,
@@ -110,8 +110,8 @@ bool EngineInitCmd::Exec() const {
110110
bool unused) {
111111
// try to unzip the downloaded file
112112
std::filesystem::path downloadedEnginePath{absolute_path};
113-
LOG_INFO << "Downloaded engine path: "
114-
<< downloadedEnginePath.string();
113+
CTLOG_INFO("Downloaded engine path: "
114+
<< downloadedEnginePath.string());
115115

116116
archive_utils::ExtractArchive(
117117
downloadedEnginePath.string(),
@@ -123,9 +123,9 @@ bool EngineInitCmd::Exec() const {
123123
try {
124124
std::filesystem::remove(absolute_path);
125125
} catch (const std::exception& e) {
126-
LOG_ERROR << "Could not delete file: " << e.what();
126+
CTLOG_WARN("Could not delete file: " << e.what());
127127
}
128-
LOG_INFO << "Finished!";
128+
CTLOG_INFO("Finished!");
129129
});
130130
if (system_info.os == "mac" || engineName_ == "cortex.onnx") {
131131
return false;
@@ -135,12 +135,13 @@ bool EngineInitCmd::Exec() const {
135135
const std::string cuda_toolkit_file_name = "cuda.tar.gz";
136136
const std::string download_id = "cuda";
137137

138-
auto gpu_driver_version = system_info_utils::GetDriverVersion();
138+
auto gpu_driver_version = system_info_utils::GetDriverVersion();
139+
if(gpu_driver_version.empty()) return true;
139140

140141
auto cuda_runtime_version =
141142
cuda_toolkit_utils::GetCompatibleCudaToolkitVersion(
142143
gpu_driver_version, system_info.os, engineName_);
143-
144+
LOG_INFO << "abc";
144145
std::ostringstream cuda_toolkit_path;
145146
cuda_toolkit_path << "dist/cuda-dependencies/" << 11.7 << "/"
146147
<< system_info.os << "/"

engine/commands/model_get_cmd.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
#include <filesystem>
33
#include <iostream>
44
#include <vector>
5+
#include "cmd_info.h"
56
#include "config/yaml_config.h"
67
#include "trantor/utils/Logger.h"
78
#include "utils/cortex_utils.h"
9+
#include "utils/logging_utils.h"
810

911
namespace commands {
1012

@@ -14,12 +16,15 @@ ModelGetCmd::ModelGetCmd(std::string model_handle)
1416
void ModelGetCmd::Exec() {
1517
if (std::filesystem::exists(cortex_utils::models_folder) &&
1618
std::filesystem::is_directory(cortex_utils::models_folder)) {
19+
CmdInfo ci(model_handle_);
20+
std::string model_file =
21+
ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch;
1722
bool found_model = false;
1823
// Iterate through directory
1924
for (const auto& entry :
2025
std::filesystem::directory_iterator(cortex_utils::models_folder)) {
2126

22-
if (entry.is_regular_file() && entry.path().stem() == model_handle_ &&
27+
if (entry.is_regular_file() && entry.path().stem() == model_file &&
2328
entry.path().extension() == ".yaml") {
2429
try {
2530
config::YamlHandler handler;
@@ -131,11 +136,16 @@ void ModelGetCmd::Exec() {
131136
found_model = true;
132137
break;
133138
} catch (const std::exception& e) {
134-
LOG_ERROR << "Error reading yaml file '" << entry.path().string()
135-
<< "': " << e.what();
139+
CTLOG_ERROR("Error reading yaml file '" << entry.path().string()
140+
<< "': " << e.what());
136141
}
137142
}
138143
}
144+
if (!found_model) {
145+
CLI_LOG("Model not found!");
146+
}
147+
} else {
148+
CLI_LOG("Model not found!");
139149
}
140150
}
141151
}; // namespace commands

engine/commands/model_list_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vector>
99
#include "config/yaml_config.h"
1010
#include "trantor/utils/Logger.h"
11+
#include "utils/logging_utils.h"
1112
namespace commands {
1213

1314
void ModelListCmd::Exec() {
@@ -30,8 +31,8 @@ void ModelListCmd::Exec() {
3031
table.add_row({std::to_string(count), model_config.id,
3132
model_config.engine, model_config.version});
3233
} catch (const std::exception& e) {
33-
LOG_ERROR << "Error reading yaml file '" << entry.path().string()
34-
<< "': " << e.what();
34+
CTLOG_ERROR("Error reading yaml file '" << entry.path().string()
35+
<< "': " << e.what());
3536
}
3637
}
3738
}

engine/commands/model_pull_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "trantor/utils/Logger.h"
55
#include "utils/cortexso_parser.h"
66
#include "utils/model_callback_utils.h"
7+
#include "utils/logging_utils.h"
78

89
namespace commands {
910
ModelPullCmd::ModelPullCmd(std::string model_handle, std::string branch)
@@ -15,10 +16,10 @@ bool ModelPullCmd::Exec() {
1516
DownloadService downloadService;
1617
downloadService.AddDownloadTask(downloadTask.value(),
1718
model_callback_utils::DownloadModelCb);
18-
std::cout << "Download finished" << std::endl;
19+
CTLOG_INFO("Download finished");
1920
return true;
2021
} else {
21-
std::cout << "Model not found" << std::endl;
22+
CTLOG_ERROR("Model not found");
2223
return false;
2324
}
2425
}

engine/commands/model_start_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "httplib.h"
33
#include "nlohmann/json.hpp"
44
#include "trantor/utils/Logger.h"
5+
#include "utils/logging_utils.h"
56

67
namespace commands {
78
ModelStartCmd::ModelStartCmd(std::string host, int port,
@@ -32,11 +33,11 @@ bool ModelStartCmd::Exec() {
3233
data_str.data(), data_str.size(), "application/json");
3334
if (res) {
3435
if (res->status == httplib::StatusCode::OK_200) {
35-
LOG_INFO << res->body;
36+
CLI_LOG("Model loaded!");
3637
}
3738
} else {
3839
auto err = res.error();
39-
LOG_WARN << "HTTP error: " << httplib::to_string(err);
40+
CTLOG_ERROR("HTTP error: " << httplib::to_string(err));
4041
return false;
4142
}
4243
return true;

engine/commands/stop_model_cmd.cc renamed to engine/commands/model_stop_cmd.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
#include "stop_model_cmd.h"
1+
#include "model_stop_cmd.h"
22
#include "httplib.h"
33
#include "nlohmann/json.hpp"
44
#include "trantor/utils/Logger.h"
5+
#include "utils/logging_utils.h"
56

67
namespace commands {
7-
StopModelCmd::StopModelCmd(std::string host, int port,
8+
ModelStopCmd::ModelStopCmd(std::string host, int port,
89
const config::ModelConfig& mc)
910
: host_(std::move(host)), port_(port), mc_(mc) {}
1011

11-
void StopModelCmd::Exec() {
12+
void ModelStopCmd::Exec() {
1213
httplib::Client cli(host_ + ":" + std::to_string(port_));
1314
nlohmann::json json_data;
1415
json_data["model"] = mc_.name;
@@ -20,11 +21,12 @@ void StopModelCmd::Exec() {
2021
data_str.data(), data_str.size(), "application/json");
2122
if (res) {
2223
if (res->status == httplib::StatusCode::OK_200) {
23-
LOG_INFO << res->body;
24+
// LOG_INFO << res->body;
25+
CLI_LOG("Model unloaded!");
2426
}
2527
} else {
2628
auto err = res.error();
27-
LOG_WARN << "HTTP error: " << httplib::to_string(err);
29+
CTLOG_ERROR("HTTP error: " << httplib::to_string(err));
2830
}
2931
}
3032

engine/commands/stop_model_cmd.h renamed to engine/commands/model_stop_cmd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
namespace commands {
77

8-
class StopModelCmd{
8+
class ModelStopCmd{
99
public:
10-
StopModelCmd(std::string host, int port, const config::ModelConfig& mc);
10+
ModelStopCmd(std::string host, int port, const config::ModelConfig& mc);
1111
void Exec();
1212

1313
private:

engine/commands/run_cmd.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ void RunCmd::Exec() {
3434
{
3535
if (!IsEngineExisted(ci.engine_name)) {
3636
EngineInitCmd eic(ci.engine_name, "");
37-
if (!eic.Exec())
37+
if (!eic.Exec()) {
38+
LOG_INFO << "Failed to install engine";
3839
return;
40+
}
3941
}
4042
}
4143

0 commit comments

Comments
 (0)