Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add engine uninstall command #1094

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions engine/commands/engine_get_cmd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "engine_get_cmd.h"
#include <iostream>
#include <tabulate/table.hpp>
#include "services/engine_service.h"
#include "utils/logging_utils.h"

namespace commands {

void EngineGetCmd::Exec() const {
CTL_INF("[EngineGetCmd] engine: " << engine_);

auto engine_service = EngineService();
try {
auto status = engine_service.GetEngineInfo(engine_);
tabulate::Table table;
table.add_row({"name", "description", "version", "product name", "status"});
table.format().font_color(tabulate::Color::green);
table.add_row({status.name, status.description, status.version,
status.product_name, status.status});
std::cout << table << std::endl;
} catch (const std::runtime_error& e) {
std::cerr << "Engine " << engine_ << " is not supported!" << "\n";
} catch (const std::exception& e) {
std::cerr << "Failed to get engine info for " << engine_ << ": " << e.what()
<< "\n";
}
}
}; // namespace commands
15 changes: 15 additions & 0 deletions engine/commands/engine_get_cmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string>

namespace commands {
class EngineGetCmd {
public:
EngineGetCmd(const std::string& engine) : engine_{engine} {};

void Exec() const;

private:
std::string engine_;
};
} // namespace commands
9 changes: 5 additions & 4 deletions engine/commands/engine_init_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool EngineInitCmd::Exec() const {
if (system_info.arch == system_info_utils::kUnsupported ||
system_info.os == system_info_utils::kUnsupported) {
CTL_ERR("Unsupported OS or architecture: " << system_info.os << ", "
<< system_info.arch);
<< system_info.arch);
return false;
}
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
Expand Down Expand Up @@ -192,9 +192,10 @@ 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) {
CTL_ERR("Your Cuda driver version " << cuda_driver_version
<< " is not compatible with cuda toolkit version "
<< suitable_toolkit_version);
CTL_ERR("Your Cuda driver version "
<< cuda_driver_version
<< " is not compatible with cuda toolkit version "
<< suitable_toolkit_version);
return false;
}

Expand Down
62 changes: 10 additions & 52 deletions engine/commands/engine_list_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,65 +1,24 @@
// clang-format off
#include "utils/cortex_utils.h"
// clang-format on
#include "engine_list_cmd.h"
#include <filesystem>
#include <tabulate/table.hpp>
#include <utility>
#include "trantor/utils/Logger.h"
#include "services/engine_service.h"

namespace commands {

bool EngineListCmd::Exec() {
auto engine_service = EngineService();
auto status_list = engine_service.GetEngineInfoList();

tabulate::Table table;
table.format().font_color(tabulate::Color::green);
table.add_row(
{"(Index)", "name", "description", "version", "product name", "status"});
table.format().font_color(tabulate::Color::green);
#ifdef _WIN32
if (std::filesystem::exists(std::filesystem::current_path().string() +
cortex_utils::kOnnxLibPath)) {
table.add_row({"1", "cortex.onnx",
"This extension enables chat completion API calls using the "
"Onnx engine",
"0.0.1", "Onnx Inference Engine", "ready"});
} else {
table.add_row({"1", "cortex.onnx",
"This extension enables chat completion API calls using the "
"Onnx engine",
"0.0.1", "Onnx Inference Engine", "not_initialized"});
for (int i = 0; i < status_list.size(); i++) {
auto status = status_list[i];
std::string index = std::to_string(i + 1);
table.add_row({index, status.name, status.description, status.version,
status.product_name, status.status});
}

#else
table.add_row(
{"1", "cortex.onnx",
"This extension enables chat completion API calls using the Onnx engine",
"0.0.1", "Onnx Inference Engine", "not_supported"});
#endif
// lllamacpp
if (std::filesystem::exists(std::filesystem::current_path().string() +
cortex_utils::kLlamaLibPath)) {
table.add_row({"2", "cortex.llamacpp",
"This extension enables chat completion API calls using the "
"LlamaCPP engine",
"0.0.1", "LlamaCPP Inference Engine", "ready"});
} else {
table.add_row({"2", "cortex.llamacpp",
"This extension enables chat completion API calls using the "
"LlamaCPP engine",
"0.0.1", "LlamaCPP Inference Engine", "not_initialized"});
}
// tensorrt llm
if (std::filesystem::exists(std::filesystem::current_path().string() +
cortex_utils::kTensorrtLlmPath)) {
table.add_row({"3", "cortex.tensorrt-llm",
"This extension enables chat completion API calls using the "
"TensorrtLLM engine",
"0.0.1", "TensorrtLLM Inference Engine", "ready"});
} else {
table.add_row({"3", "cortex.tensorrt-llm",
"This extension enables chat completion API calls using the "
"TensorrtLLM engine",
"0.0.1", "TensorrtLLM Inference Engine", "not_initialized"});
}
for (int i = 0; i < 6; i++) {
table[0][i]
.format()
Expand All @@ -77,5 +36,4 @@ bool EngineListCmd::Exec() {
std::cout << table << std::endl;
return true;
}

}; // namespace commands
6 changes: 2 additions & 4 deletions engine/commands/engine_list_cmd.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include <string>

namespace commands {
class EngineListCmd {
public:
bool Exec() ;
bool Exec();
};

} // namespace commands
} // namespace commands
21 changes: 21 additions & 0 deletions engine/commands/engine_uninstall_cmd.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "engine_uninstall_cmd.h"
#include "services/engine_service.h"
#include "utils/logging_utils.h"

namespace commands {

EngineUninstallCmd::EngineUninstallCmd(std::string engine)
: engine_{std::move(engine)} {}

void EngineUninstallCmd::Exec() const {
CTL_INF("Uninstall engine " + engine_);
auto engine_service = EngineService();

try {
engine_service.UninstallEngine(engine_);
CLI_LOG("Engine " << engine_ << " uninstalled successfully!")
} catch (const std::exception& e) {
CLI_LOG("Failed to uninstall engine " << engine_ << ": " << e.what());
}
}
}; // namespace commands
18 changes: 18 additions & 0 deletions engine/commands/engine_uninstall_cmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include <array>
#include <string>

namespace commands {
class EngineUninstallCmd {
public:
EngineUninstallCmd(std::string engine);

void Exec() const;

private:
std::string engine_;

static constexpr std::array<const char*, 3> supportedEngines_ = {
namchuai marked this conversation as resolved.
Show resolved Hide resolved
"cortex.llamacpp", "cortex.onnx", "cortex.tensorrt-llm"};
};
} // namespace commands
5 changes: 2 additions & 3 deletions engine/commands/model_pull_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "model_pull_cmd.h"
#include <utility>
#include "services/download_service.h"
#include "trantor/utils/Logger.h"
#include "utils/cortexso_parser.h"
#include "utils/model_callback_utils.h"
#include "utils/logging_utils.h"
#include "utils/model_callback_utils.h"

namespace commands {
ModelPullCmd::ModelPullCmd(std::string model_handle, std::string branch)
Expand All @@ -24,4 +23,4 @@ bool ModelPullCmd::Exec() {
}
}

}; // namespace commands
}; // namespace commands
2 changes: 1 addition & 1 deletion engine/commands/model_start_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ bool ModelStartCmd::Exec() {
return true;
}

}; // namespace commands
}; // namespace commands
8 changes: 4 additions & 4 deletions engine/commands/model_start_cmd.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#pragma once
#include <string>
#include <optional>
#include "config/model_config.h"

namespace commands {

class ModelStartCmd{
class ModelStartCmd {
public:
explicit ModelStartCmd(std::string host, int port, const config::ModelConfig& mc);
explicit ModelStartCmd(std::string host, int port,
const config::ModelConfig& mc);
bool Exec();

private:
std::string host_;
int port_;
const config::ModelConfig& mc_;
};
} // namespace commands
} // namespace commands
5 changes: 2 additions & 3 deletions engine/commands/run_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "cmd_info.h"
#include "config/yaml_config.h"
#include "engine_init_cmd.h"
#include "httplib.h"
#include "model_pull_cmd.h"
#include "model_start_cmd.h"
#include "trantor/utils/Logger.h"
Expand Down Expand Up @@ -37,7 +36,7 @@ void RunCmd::Exec() {
if (!eic.Exec()) {
LOG_INFO << "Failed to install engine";
return;
}
}
}
}

Expand Down Expand Up @@ -95,4 +94,4 @@ bool RunCmd::IsEngineExisted(const std::string& e) {
return false;
}

}; // namespace commands
}; // namespace commands
44 changes: 35 additions & 9 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include "command_line_parser.h"
#include "commands/chat_cmd.h"
#include "commands/cmd_info.h"
#include "commands/engine_get_cmd.h"
#include "commands/engine_init_cmd.h"
#include "commands/engine_list_cmd.h"
#include "commands/engine_uninstall_cmd.h"
#include "commands/model_get_cmd.h"
#include "commands/model_list_cmd.h"
#include "commands/model_pull_cmd.h"
#include "commands/model_start_cmd.h"
#include "commands/run_cmd.h"
#include "commands/model_stop_cmd.h"
#include "commands/run_cmd.h"
#include "commands/server_stop_cmd.h"
#include "config/yaml_config.h"
#include "services/engine_service.h"
#include "utils/cortex_utils.h"
#include "utils/logging_utils.h"

Expand Down Expand Up @@ -124,11 +127,11 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
command.Exec();
});

auto get_engine_cmd = engines_cmd->add_subcommand("get", "Get an engine");
EngineManagement(engines_cmd, "cortex.llamacpp", version);
EngineManagement(engines_cmd, "cortex.onnx", version);
EngineManagement(engines_cmd, "cortex.tensorrt-llm", version);

EngineInstall(engines_cmd, "cortex.llamacpp", version);
EngineInstall(engines_cmd, "cortex.onnx", version);
EngineInstall(engines_cmd, "cortex.tensorrt-llm", version);
EngineGet(engines_cmd);
}

{
Expand Down Expand Up @@ -157,9 +160,9 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
return true;
}

void CommandLineParser::EngineInstall(CLI::App* parent,
const std::string& engine_name,
std::string& version) {
void CommandLineParser::EngineManagement(CLI::App* parent,
const std::string& engine_name,
std::string& version) {
auto engine_cmd =
parent->add_subcommand(engine_name, "Manage " + engine_name + " engine");

Expand All @@ -172,4 +175,27 @@ void CommandLineParser::EngineInstall(CLI::App* parent,
commands::EngineInitCmd eic(engine_name, version);
eic.Exec();
});
}

auto uninstall_desc{"Uninstall " + engine_name + " engine"};
auto uninstall_cmd = engine_cmd->add_subcommand("uninstall", uninstall_desc);
uninstall_cmd->callback([engine_name] {
commands::EngineUninstallCmd cmd(engine_name);
cmd.Exec();
});
}

void CommandLineParser::EngineGet(CLI::App* parent) {
auto get_cmd = parent->add_subcommand("get", "Get an engine info");
auto engine_service = EngineService();

for (auto& engine : engine_service.kSupportEngines) {
std::string engine_name{engine};
std::string desc = "Get " + engine_name + " status";

auto engine_get_cmd = get_cmd->add_subcommand(engine_name, desc);
engine_get_cmd->callback([engine_name] {
commands::EngineGetCmd cmd(engine_name);
cmd.Exec();
});
}
}
9 changes: 5 additions & 4 deletions engine/controllers/command_line_parser.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <vector>
#include "CLI/CLI.hpp"

class CommandLineParser {
Expand All @@ -9,8 +8,10 @@ class CommandLineParser {
bool SetupCommand(int argc, char** argv);

private:
void EngineInstall(CLI::App* parent, const std::string& engine_name,
std::string& version);
void EngineManagement(CLI::App* parent, const std::string& engine_name,
std::string& version);

void EngineGet(CLI::App* parent);

CLI::App app_;
};
};
Loading
Loading