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

Commit 209c06a

Browse files
authored
Merge pull request #1094 from janhq/feat/engine-uninstall
feat: add engine uninstall command
2 parents ea0f365 + a5152b0 commit 209c06a

25 files changed

+566
-173
lines changed

engine/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ if(DEBUG)
5959
add_compile_definitions(ALLOW_ALL_CORS)
6060
endif()
6161

62+
if(NOT DEFINED CORTEX_CONFIG_FILE_PATH)
63+
set(CORTEX_CONFIG_FILE_PATH "user_home")
64+
endif()
65+
6266
if(NOT DEFINED CORTEX_CPP_VERSION)
6367
set(CORTEX_CPP_VERSION "default_version")
6468
endif()
@@ -80,6 +84,7 @@ if(DEFINED CMAKE_JS_INC)
8084
endif()
8185

8286
add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}")
87+
add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}")
8388

8489
option(CMAKE_BUILD_TEST "Enable testing" OFF)
8590
if(CMAKE_BUILD_TEST)

engine/commands/engine_get_cmd.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "engine_get_cmd.h"
2+
#include <iostream>
3+
#include <tabulate/table.hpp>
4+
#include "services/engine_service.h"
5+
#include "utils/logging_utils.h"
6+
7+
namespace commands {
8+
9+
void EngineGetCmd::Exec() const {
10+
CTL_INF("[EngineGetCmd] engine: " << engine_);
11+
12+
auto engine_service = EngineService();
13+
try {
14+
auto status = engine_service.GetEngineInfo(engine_);
15+
tabulate::Table table;
16+
table.add_row({"name", "description", "version", "product name", "status"});
17+
table.format().font_color(tabulate::Color::green);
18+
table.add_row({status.name, status.description, status.version,
19+
status.product_name, status.status});
20+
std::cout << table << std::endl;
21+
} catch (const std::runtime_error& e) {
22+
std::cerr << "Engine " << engine_ << " is not supported!" << "\n";
23+
} catch (const std::exception& e) {
24+
std::cerr << "Failed to get engine info for " << engine_ << ": " << e.what()
25+
<< "\n";
26+
}
27+
}
28+
}; // namespace commands

engine/commands/engine_get_cmd.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace commands {
6+
class EngineGetCmd {
7+
public:
8+
EngineGetCmd(const std::string& engine) : engine_{engine} {};
9+
10+
void Exec() const;
11+
12+
private:
13+
std::string engine_;
14+
};
15+
} // namespace commands

engine/commands/engine_init_cmd.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool EngineInitCmd::Exec() const {
2929
if (system_info.arch == system_info_utils::kUnsupported ||
3030
system_info.os == system_info_utils::kUnsupported) {
3131
CTL_ERR("Unsupported OS or architecture: " << system_info.os << ", "
32-
<< system_info.arch);
32+
<< system_info.arch);
3333
return false;
3434
}
3535
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
@@ -192,9 +192,10 @@ bool EngineInitCmd::Exec() const {
192192
// cuda driver version should be greater than toolkit version to ensure compatibility
193193
if (semantic_version_utils::CompareSemanticVersion(
194194
cuda_driver_version, suitable_toolkit_version) < 0) {
195-
CTL_ERR("Your Cuda driver version " << cuda_driver_version
196-
<< " is not compatible with cuda toolkit version "
197-
<< suitable_toolkit_version);
195+
CTL_ERR("Your Cuda driver version "
196+
<< cuda_driver_version
197+
<< " is not compatible with cuda toolkit version "
198+
<< suitable_toolkit_version);
198199
return false;
199200
}
200201

engine/commands/engine_list_cmd.cc

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,24 @@
1-
// clang-format off
2-
#include "utils/cortex_utils.h"
3-
// clang-format on
41
#include "engine_list_cmd.h"
5-
#include <filesystem>
62
#include <tabulate/table.hpp>
7-
#include <utility>
8-
#include "trantor/utils/Logger.h"
3+
#include "services/engine_service.h"
94

105
namespace commands {
116

127
bool EngineListCmd::Exec() {
8+
auto engine_service = EngineService();
9+
auto status_list = engine_service.GetEngineInfoList();
10+
1311
tabulate::Table table;
12+
table.format().font_color(tabulate::Color::green);
1413
table.add_row(
1514
{"(Index)", "name", "description", "version", "product name", "status"});
16-
table.format().font_color(tabulate::Color::green);
17-
#ifdef _WIN32
18-
if (std::filesystem::exists(std::filesystem::current_path().string() +
19-
cortex_utils::kOnnxLibPath)) {
20-
table.add_row({"1", "cortex.onnx",
21-
"This extension enables chat completion API calls using the "
22-
"Onnx engine",
23-
"0.0.1", "Onnx Inference Engine", "ready"});
24-
} else {
25-
table.add_row({"1", "cortex.onnx",
26-
"This extension enables chat completion API calls using the "
27-
"Onnx engine",
28-
"0.0.1", "Onnx Inference Engine", "not_initialized"});
15+
for (int i = 0; i < status_list.size(); i++) {
16+
auto status = status_list[i];
17+
std::string index = std::to_string(i + 1);
18+
table.add_row({index, status.name, status.description, status.version,
19+
status.product_name, status.status});
2920
}
3021

31-
#else
32-
table.add_row(
33-
{"1", "cortex.onnx",
34-
"This extension enables chat completion API calls using the Onnx engine",
35-
"0.0.1", "Onnx Inference Engine", "not_supported"});
36-
#endif
37-
// lllamacpp
38-
if (std::filesystem::exists(std::filesystem::current_path().string() +
39-
cortex_utils::kLlamaLibPath)) {
40-
table.add_row({"2", "cortex.llamacpp",
41-
"This extension enables chat completion API calls using the "
42-
"LlamaCPP engine",
43-
"0.0.1", "LlamaCPP Inference Engine", "ready"});
44-
} else {
45-
table.add_row({"2", "cortex.llamacpp",
46-
"This extension enables chat completion API calls using the "
47-
"LlamaCPP engine",
48-
"0.0.1", "LlamaCPP Inference Engine", "not_initialized"});
49-
}
50-
// tensorrt llm
51-
if (std::filesystem::exists(std::filesystem::current_path().string() +
52-
cortex_utils::kTensorrtLlmPath)) {
53-
table.add_row({"3", "cortex.tensorrt-llm",
54-
"This extension enables chat completion API calls using the "
55-
"TensorrtLLM engine",
56-
"0.0.1", "TensorrtLLM Inference Engine", "ready"});
57-
} else {
58-
table.add_row({"3", "cortex.tensorrt-llm",
59-
"This extension enables chat completion API calls using the "
60-
"TensorrtLLM engine",
61-
"0.0.1", "TensorrtLLM Inference Engine", "not_initialized"});
62-
}
6322
for (int i = 0; i < 6; i++) {
6423
table[0][i]
6524
.format()
@@ -77,5 +36,4 @@ bool EngineListCmd::Exec() {
7736
std::cout << table << std::endl;
7837
return true;
7938
}
80-
8139
}; // namespace commands

engine/commands/engine_list_cmd.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#pragma once
22

3-
#include <string>
4-
53
namespace commands {
64
class EngineListCmd {
75
public:
8-
bool Exec() ;
6+
bool Exec();
97
};
108

11-
} // namespace commands
9+
} // namespace commands
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "engine_uninstall_cmd.h"
2+
#include "services/engine_service.h"
3+
#include "utils/logging_utils.h"
4+
5+
namespace commands {
6+
7+
EngineUninstallCmd::EngineUninstallCmd(std::string engine)
8+
: engine_{std::move(engine)} {}
9+
10+
void EngineUninstallCmd::Exec() const {
11+
CTL_INF("Uninstall engine " + engine_);
12+
auto engine_service = EngineService();
13+
14+
try {
15+
engine_service.UninstallEngine(engine_);
16+
CLI_LOG("Engine " << engine_ << " uninstalled successfully!")
17+
} catch (const std::exception& e) {
18+
CLI_LOG("Failed to uninstall engine " << engine_ << ": " << e.what());
19+
}
20+
}
21+
}; // namespace commands
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace commands {
6+
class EngineUninstallCmd {
7+
public:
8+
EngineUninstallCmd(std::string engine);
9+
10+
void Exec() const;
11+
12+
private:
13+
std::string engine_;
14+
};
15+
} // namespace commands

engine/commands/model_pull_cmd.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#include "model_pull_cmd.h"
22
#include <utility>
33
#include "services/download_service.h"
4-
#include "trantor/utils/Logger.h"
54
#include "utils/cortexso_parser.h"
6-
#include "utils/model_callback_utils.h"
75
#include "utils/logging_utils.h"
6+
#include "utils/model_callback_utils.h"
87

98
namespace commands {
109
ModelPullCmd::ModelPullCmd(std::string model_handle, std::string branch)
@@ -24,4 +23,4 @@ bool ModelPullCmd::Exec() {
2423
}
2524
}
2625

27-
}; // namespace commands
26+
}; // namespace commands

engine/commands/model_start_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ bool ModelStartCmd::Exec() {
4343
return true;
4444
}
4545

46-
}; // namespace commands
46+
}; // namespace commands

0 commit comments

Comments
 (0)