Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions engine/commands/chat_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "httplib.h"

#include "trantor/utils/Logger.h"
#include "utils/logging_utils.h"

namespace commands {
namespace {
Expand Down Expand Up @@ -48,12 +49,12 @@ void ChatCmd::Exec(std::string msg) {
data_str.data(), data_str.size(), "application/json");
if (res) {
if (res->status != httplib::StatusCode::OK_200) {
LOG_INFO << res->body;
CTL_ERR(res->body);
return;
}
} else {
auto err = res.error();
LOG_WARN << "HTTP error: " << httplib::to_string(err);
CTL_ERR("HTTP error: " << httplib::to_string(err));
return;
}
}
Expand Down
5 changes: 3 additions & 2 deletions engine/commands/cmd_info.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cmd_info.h"
#include <vector>
#include "trantor/utils/Logger.h"
#include "utils/logging_utils.h"

namespace commands {
namespace {
Expand Down Expand Up @@ -33,7 +34,7 @@ void CmdInfo::Parse(std::string model_id) {
} else {
auto res = split(model_id, kDelimiter);
if (res.size() != 2) {
LOG_ERROR << "model_id does not valid";
CTL_ERR("<model_id> does not valid");
return;
} else {
model_name = std::move(res[0]);
Expand All @@ -45,7 +46,7 @@ void CmdInfo::Parse(std::string model_id) {
} else if (branch.find("gguf") != std::string::npos) {
engine_name = "cortex.llamacpp";
} else {
LOG_ERROR << "Not a valid branch model_name " << branch;
CTL_ERR("Not a valid branch model_name " << branch);
}
}
}
Expand Down
42 changes: 21 additions & 21 deletions engine/commands/engine_init_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ EngineInitCmd::EngineInitCmd(std::string engineName, std::string version)

bool EngineInitCmd::Exec() const {
if (engineName_.empty()) {
LOG_ERROR << "Engine name is required";
CTL_ERR("Engine name is required");
return false;
}

// Check if the architecture and OS are supported
auto system_info = system_info_utils::GetSystemInfo();
if (system_info.arch == system_info_utils::kUnsupported ||
system_info.os == system_info_utils::kUnsupported) {
LOG_ERROR << "Unsupported OS or architecture: " << system_info.os << ", "
<< system_info.arch;
CTL_ERR("Unsupported OS or architecture: " << system_info.os << ", "
<< system_info.arch);
return false;
}
LOG_INFO << "OS: " << system_info.os << ", Arch: " << system_info.arch;
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);

// check if engine is supported
if (std::find(supportedEngines_.begin(), supportedEngines_.end(),
engineName_) == supportedEngines_.end()) {
LOG_ERROR << "Engine not supported";
CTL_ERR("Engine not supported");
return false;
}

Expand All @@ -46,7 +46,7 @@ bool EngineInitCmd::Exec() const {
std::ostringstream engineReleasePath;
engineReleasePath << "/repos/janhq/" << engineName_ << "/releases/"
<< version;
LOG_INFO << "Engine release path: " << gitHubHost << engineReleasePath.str();
CTL_INF("Engine release path: " << gitHubHost << engineReleasePath.str());
using namespace nlohmann;

httplib::Client cli(gitHubHost);
Expand All @@ -64,10 +64,10 @@ bool EngineInitCmd::Exec() const {
}

auto cuda_driver_version = system_info_utils::GetCudaVersion();
LOG_INFO << "Engine: " << engineName_
<< ", CUDA driver version: " << cuda_driver_version;
CTL_INF("engineName_: " << engineName_);
CTL_INF("CUDA version: " << cuda_driver_version);
std::string matched_variant = "";

std::string matched_variant{""};
if (engineName_ == "cortex.tensorrt-llm") {
matched_variant = engine_matcher_utils::ValidateTensorrtLlm(
variants, system_info.os, cuda_driver_version);
Expand All @@ -80,9 +80,9 @@ bool EngineInitCmd::Exec() const {
variants, system_info.os, system_info.arch, suitable_avx,
cuda_driver_version);
}
LOG_INFO << "Matched variant: " << matched_variant;
CTL_INF("Matched variant: " << matched_variant);
if (matched_variant.empty()) {
LOG_ERROR << "No variant found for " << os_arch;
CTL_ERR("No variant found for " << os_arch);
return false;
}

Expand All @@ -95,7 +95,7 @@ bool EngineInitCmd::Exec() const {
std::string path = full_url.substr(host.length());

auto fileName = asset["name"].get<std::string>();
LOG_INFO << "URL: " << full_url;
CTL_INF("URL: " << full_url);

auto downloadTask = DownloadTask{.id = engineName_,
.type = DownloadType::Engine,
Expand All @@ -115,8 +115,8 @@ bool EngineInitCmd::Exec() const {
bool unused) {
// try to unzip the downloaded file
std::filesystem::path downloadedEnginePath{absolute_path};
LOG_INFO << "Downloaded engine path: "
<< downloadedEnginePath.string();
CTL_INF(
"Downloaded engine path: " << downloadedEnginePath.string());

std::filesystem::path extract_path =
downloadedEnginePath.parent_path().parent_path();
Expand Down Expand Up @@ -156,9 +156,9 @@ bool EngineInitCmd::Exec() const {
try {
std::filesystem::remove(absolute_path);
} catch (const std::exception& e) {
LOG_ERROR << "Could not delete file: " << e.what();
CTL_WRN("Could not delete file: " << e.what());
}
LOG_INFO << "Finished!";
CTL_INF("Finished!");
});
if (system_info.os == "mac" || engineName_ == "cortex.onnx") {
// mac and onnx engine does not require cuda toolkit
Expand Down Expand Up @@ -192,9 +192,9 @@ bool EngineInitCmd::Exec() const {
// cuda driver version should be greater than toolkit version to ensure compatibility
if (semantic_version_utils::CompareSemanticVersion(
cuda_driver_version, suitable_toolkit_version) < 0) {
LOG_ERROR << "Your Cuda driver version " << cuda_driver_version
CTL_ERR("Your Cuda driver version " << cuda_driver_version
<< " is not compatible with cuda toolkit version "
<< suitable_toolkit_version;
<< suitable_toolkit_version);
return false;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ bool EngineInitCmd::Exec() const {
try {
std::filesystem::remove(absolute_path);
} catch (std::exception& e) {
LOG_ERROR << "Error removing downloaded file: " << e.what();
CTL_ERR("Error removing downloaded file: " << e.what());
}
});

Expand All @@ -245,12 +245,12 @@ bool EngineInitCmd::Exec() const {
return false;
}
} else {
LOG_ERROR << "HTTP error: " << res->status;
CTL_ERR("HTTP error: " << res->status);
return false;
}
} else {
auto err = res.error();
LOG_ERROR << "HTTP error: " << httplib::to_string(err);
CTL_ERR("HTTP error: " << httplib::to_string(err));
return false;
}
return true;
Expand Down
16 changes: 13 additions & 3 deletions engine/commands/model_get_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include <filesystem>
#include <iostream>
#include <vector>
#include "cmd_info.h"
#include "config/yaml_config.h"
#include "trantor/utils/Logger.h"
#include "utils/cortex_utils.h"
#include "utils/logging_utils.h"

namespace commands {

Expand All @@ -14,12 +16,15 @@ ModelGetCmd::ModelGetCmd(std::string model_handle)
void ModelGetCmd::Exec() {
if (std::filesystem::exists(cortex_utils::models_folder) &&
std::filesystem::is_directory(cortex_utils::models_folder)) {
CmdInfo ci(model_handle_);
std::string model_file =
ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch;
bool found_model = false;
// Iterate through directory
for (const auto& entry :
std::filesystem::directory_iterator(cortex_utils::models_folder)) {

if (entry.is_regular_file() && entry.path().stem() == model_handle_ &&
if (entry.is_regular_file() && entry.path().stem() == model_file &&
entry.path().extension() == ".yaml") {
try {
config::YamlHandler handler;
Expand Down Expand Up @@ -131,11 +136,16 @@ void ModelGetCmd::Exec() {
found_model = true;
break;
} catch (const std::exception& e) {
LOG_ERROR << "Error reading yaml file '" << entry.path().string()
<< "': " << e.what();
CTL_ERR("Error reading yaml file '" << entry.path().string()
<< "': " << e.what());
}
}
}
if (!found_model) {
CLI_LOG("Model not found!");
}
} else {
CLI_LOG("Model not found!");
}
}
}; // namespace commands
5 changes: 3 additions & 2 deletions engine/commands/model_list_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include "config/yaml_config.h"
#include "trantor/utils/Logger.h"
#include "utils/logging_utils.h"
namespace commands {

void ModelListCmd::Exec() {
Expand All @@ -30,8 +31,8 @@ void ModelListCmd::Exec() {
table.add_row({std::to_string(count), model_config.id,
model_config.engine, model_config.version});
} catch (const std::exception& e) {
LOG_ERROR << "Error reading yaml file '" << entry.path().string()
<< "': " << e.what();
CTL_ERR("Error reading yaml file '" << entry.path().string()
<< "': " << e.what());
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions engine/commands/model_pull_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "trantor/utils/Logger.h"
#include "utils/cortexso_parser.h"
#include "utils/model_callback_utils.h"
#include "utils/logging_utils.h"

namespace commands {
ModelPullCmd::ModelPullCmd(std::string model_handle, std::string branch)
Expand All @@ -15,10 +16,10 @@ bool ModelPullCmd::Exec() {
DownloadService downloadService;
downloadService.AddDownloadTask(downloadTask.value(),
model_callback_utils::DownloadModelCb);
std::cout << "Download finished" << std::endl;
CTL_INF("Download finished");
return true;
} else {
std::cout << "Model not found" << std::endl;
CTL_ERR("Model not found");
return false;
}
}
Expand Down
5 changes: 3 additions & 2 deletions engine/commands/model_start_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "httplib.h"
#include "nlohmann/json.hpp"
#include "trantor/utils/Logger.h"
#include "utils/logging_utils.h"

namespace commands {
ModelStartCmd::ModelStartCmd(std::string host, int port,
Expand Down Expand Up @@ -32,11 +33,11 @@ bool ModelStartCmd::Exec() {
data_str.data(), data_str.size(), "application/json");
if (res) {
if (res->status == httplib::StatusCode::OK_200) {
LOG_INFO << res->body;
CLI_LOG("Model loaded!");
}
} else {
auto err = res.error();
LOG_WARN << "HTTP error: " << httplib::to_string(err);
CTL_ERR("HTTP error: " << httplib::to_string(err));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "stop_model_cmd.h"
#include "model_stop_cmd.h"
#include "httplib.h"
#include "nlohmann/json.hpp"
#include "trantor/utils/Logger.h"
#include "utils/logging_utils.h"

namespace commands {
StopModelCmd::StopModelCmd(std::string host, int port,
ModelStopCmd::ModelStopCmd(std::string host, int port,
const config::ModelConfig& mc)
: host_(std::move(host)), port_(port), mc_(mc) {}

void StopModelCmd::Exec() {
void ModelStopCmd::Exec() {
httplib::Client cli(host_ + ":" + std::to_string(port_));
nlohmann::json json_data;
json_data["model"] = mc_.name;
Expand All @@ -20,11 +21,12 @@ void StopModelCmd::Exec() {
data_str.data(), data_str.size(), "application/json");
if (res) {
if (res->status == httplib::StatusCode::OK_200) {
LOG_INFO << res->body;
// LOG_INFO << res->body;
CLI_LOG("Model unloaded!");
}
} else {
auto err = res.error();
LOG_WARN << "HTTP error: " << httplib::to_string(err);
CTL_ERR("HTTP error: " << httplib::to_string(err));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace commands {

class StopModelCmd{
class ModelStopCmd{
public:
StopModelCmd(std::string host, int port, const config::ModelConfig& mc);
ModelStopCmd(std::string host, int port, const config::ModelConfig& mc);
void Exec();

private:
Expand Down
4 changes: 3 additions & 1 deletion engine/commands/run_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ void RunCmd::Exec() {
{
if (!IsEngineExisted(ci.engine_name)) {
EngineInitCmd eic(ci.engine_name, "");
if (!eic.Exec())
if (!eic.Exec()) {
LOG_INFO << "Failed to install engine";
return;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#include "stop_server_cmd.h"
#include "server_stop_cmd.h"
#include "httplib.h"
#include "trantor/utils/Logger.h"
#include "utils/logging_utils.h"

namespace commands {
StopServerCmd::StopServerCmd(std::string host, int port)
ServerStopCmd::ServerStopCmd(std::string host, int port)
: host_(std::move(host)), port_(port) {}

void StopServerCmd::Exec() {
void ServerStopCmd::Exec() {
httplib::Client cli(host_ + ":" + std::to_string(port_));
auto res = cli.Delete("/processManager/destroy");
if (res) {
LOG_INFO << res->body;
CLI_LOG("Server stopped!");
} else {
auto err = res.error();
LOG_WARN << "HTTP error: " << httplib::to_string(err);
CTL_ERR("HTTP error: " << httplib::to_string(err));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace commands {

class StopServerCmd{
class ServerStopCmd{
public:
StopServerCmd(std::string host, int port);
ServerStopCmd(std::string host, int port);
void Exec();

private:
Expand Down
Loading