Skip to content

Commit

Permalink
feat: install local engine (#1292)
Browse files Browse the repository at this point in the history
* temp

* feat: next

* feat: more

* fix: add e2e tests

* fix: refactor

* fix: build ubuntu

* fix: explicit constructor

* fix: comments

* fix: cuda version

* fix: jan_host

* fix: correct cuda version
  • Loading branch information
vansangpfiev authored Sep 23, 2024
1 parent 80a1a70 commit 1e7c2ac
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 137 deletions.
12 changes: 6 additions & 6 deletions engine/commands/cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void CortexUpdCmd::Exec(std::string v) {

bool CortexUpdCmd::GetStable(const std::string& v) {
auto system_info = system_info_utils::GetSystemInfo();
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
CTL_INF("OS: " << system_info->os << ", Arch: " << system_info->arch);

// Download file
auto github_host = GetHostName();
Expand All @@ -67,7 +67,7 @@ bool CortexUpdCmd::GetStable(const std::string& v) {
}

if (!HandleGithubRelease(json_data["assets"],
{system_info.os + "-" + system_info.arch})) {
{system_info->os + "-" + system_info->arch})) {
return false;
}
} catch (const nlohmann::json::parse_error& e) {
Expand Down Expand Up @@ -103,7 +103,7 @@ bool CortexUpdCmd::GetStable(const std::string& v) {

bool CortexUpdCmd::GetBeta(const std::string& v) {
auto system_info = system_info_utils::GetSystemInfo();
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
CTL_INF("OS: " << system_info->os << ", Arch: " << system_info->arch);

// Download file
auto github_host = GetHostName();
Expand Down Expand Up @@ -133,7 +133,7 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
}

if (!HandleGithubRelease(json_data["assets"],
{system_info.os + "-" + system_info.arch})) {
{system_info->os + "-" + system_info->arch})) {
return false;
}
} catch (const nlohmann::json::parse_error& e) {
Expand Down Expand Up @@ -234,11 +234,11 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,

bool CortexUpdCmd::GetNightly(const std::string& v) {
auto system_info = system_info_utils::GetSystemInfo();
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
CTL_INF("OS: " << system_info->os << ", Arch: " << system_info->arch);

// Download file
std::string version = v.empty() ? "latest" : std::move(v);
std::string os_arch{system_info.os + "-" + system_info.arch};
std::string os_arch{system_info->os + "-" + system_info->arch};
const char* paths[] = {
"cortex",
version.c_str(),
Expand Down
5 changes: 3 additions & 2 deletions engine/commands/engine_install_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
namespace commands {

void EngineInstallCmd::Exec(const std::string& engine,
const std::string& version) {
engine_service_.InstallEngine(engine, version);
const std::string& version,
const std::string& src) {
engine_service_.InstallEngine(engine, version, src);
CLI_LOG("Engine " << engine << " installed successfully!");
}
}; // namespace commands
3 changes: 2 additions & 1 deletion engine/commands/engine_install_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class EngineInstallCmd {
public:
explicit EngineInstallCmd() : engine_service_{EngineService()} {};

void Exec(const std::string& engine, const std::string& version = "latest");
void Exec(const std::string& engine, const std::string& version = "latest",
const std::string& src = "");

private:
EngineService engine_service_;
Expand Down
12 changes: 8 additions & 4 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ void CommandLineParser::SetupEngineCommands() {
});
for (auto& engine : engine_service_.kSupportEngines) {
std::string engine_name{engine};
EngineInstall(install_cmd, engine_name, cml_data_.engine_version);
EngineInstall(install_cmd, engine_name, cml_data_.engine_version,
cml_data_.engine_src);
}

auto uninstall_cmd =
Expand Down Expand Up @@ -395,7 +396,7 @@ void CommandLineParser::SetupSystemCommands() {

void CommandLineParser::EngineInstall(CLI::App* parent,
const std::string& engine_name,
std::string& version) {
std::string& version, std::string& src) {
auto install_engine_cmd = parent->add_subcommand(engine_name, "");
install_engine_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
" engines install " + engine_name + " [options]");
Expand All @@ -404,9 +405,12 @@ void CommandLineParser::EngineInstall(CLI::App* parent,
install_engine_cmd->add_option("-v, --version", version,
"Engine version to download");

install_engine_cmd->callback([engine_name, &version] {
install_engine_cmd->add_option("-s, --source", src,
"Install engine by local path");

install_engine_cmd->callback([engine_name, &version, &src] {
try {
commands::EngineInstallCmd().Exec(engine_name, version);
commands::EngineInstallCmd().Exec(engine_name, version, src);
} catch (const std::exception& e) {
CTL_ERR(e.what());
}
Expand Down
3 changes: 2 additions & 1 deletion engine/controllers/command_line_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CommandLineParser {
void SetupSystemCommands();

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

void EngineUninstall(CLI::App* parent, const std::string& engine_name);

Expand All @@ -35,6 +35,7 @@ class CommandLineParser {
std::string model_alias;
std::string model_path;
std::string engine_version = "latest";
std::string engine_src;
std::string cortex_version;
bool check_upd = true;
int port;
Expand Down
2 changes: 1 addition & 1 deletion engine/controllers/engines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Engines::InstallEngine(
auto jsonResponse = json::parse(res->body);
auto assets = jsonResponse["assets"];

auto os_arch{system_info.os + "-" + system_info.arch};
auto os_arch{system_info->os + "-" + system_info->arch};
for (auto& asset : assets) {
auto assetName = asset["name"].get<std::string>();
if (assetName.find(os_arch) != std::string::npos) {
Expand Down
14 changes: 14 additions & 0 deletions engine/e2e-test/test_cli_engine_install.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import platform
import tempfile

import pytest
from test_runner import run
Expand Down Expand Up @@ -36,3 +37,16 @@ def test_engines_install_pre_release_llamacpp(self):
assert "Start downloading" in output, "Should display downloading message"
assert exit_code == 0, f"Install engine failed with error: {error}"

def test_engines_should_fallback_to_download_llamacpp_engine_if_not_exists(self):
exit_code, output, error = run(
"Install Engine", ["engines", "install", "cortex.llamacpp", "-s", tempfile.gettempdir()], timeout=None
)
assert "Start downloading" in output, "Should display downloading message"
assert exit_code == 0, f"Install engine failed with error: {error}"

def test_engines_should_not_perform_with_dummy_path(self):
exit_code, output, error = run(
"Install Engine", ["engines", "install", "cortex.llamacpp", "-s", "abcpod"], timeout=None
)
assert "Folder does not exist" in output, "Should display error"
assert exit_code == 0, f"Install engine failed with error: {error}"
8 changes: 4 additions & 4 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ void RunServer() {
int main(int argc, char* argv[]) {
// Stop the program if the system is not supported
auto system_info = system_info_utils::GetSystemInfo();
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);
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);
return 1;
}

Expand Down
Loading

0 comments on commit 1e7c2ac

Please sign in to comment.