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

Commit 1e7c2ac

Browse files
authored
feat: install local engine (#1292)
* 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
1 parent 80a1a70 commit 1e7c2ac

File tree

11 files changed

+280
-137
lines changed

11 files changed

+280
-137
lines changed

engine/commands/cortex_upd_cmd.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void CortexUpdCmd::Exec(std::string v) {
4949

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

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

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

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

108108
// Download file
109109
auto github_host = GetHostName();
@@ -133,7 +133,7 @@ bool CortexUpdCmd::GetBeta(const std::string& v) {
133133
}
134134

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

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

239239
// Download file
240240
std::string version = v.empty() ? "latest" : std::move(v);
241-
std::string os_arch{system_info.os + "-" + system_info.arch};
241+
std::string os_arch{system_info->os + "-" + system_info->arch};
242242
const char* paths[] = {
243243
"cortex",
244244
version.c_str(),

engine/commands/engine_install_cmd.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
namespace commands {
1111

1212
void EngineInstallCmd::Exec(const std::string& engine,
13-
const std::string& version) {
14-
engine_service_.InstallEngine(engine, version);
13+
const std::string& version,
14+
const std::string& src) {
15+
engine_service_.InstallEngine(engine, version, src);
1516
CLI_LOG("Engine " << engine << " installed successfully!");
1617
}
1718
}; // namespace commands

engine/commands/engine_install_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class EngineInstallCmd {
99
public:
1010
explicit EngineInstallCmd() : engine_service_{EngineService()} {};
1111

12-
void Exec(const std::string& engine, const std::string& version = "latest");
12+
void Exec(const std::string& engine, const std::string& version = "latest",
13+
const std::string& src = "");
1314

1415
private:
1516
EngineService engine_service_;

engine/controllers/command_line_parser.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ void CommandLineParser::SetupEngineCommands() {
331331
});
332332
for (auto& engine : engine_service_.kSupportEngines) {
333333
std::string engine_name{engine};
334-
EngineInstall(install_cmd, engine_name, cml_data_.engine_version);
334+
EngineInstall(install_cmd, engine_name, cml_data_.engine_version,
335+
cml_data_.engine_src);
335336
}
336337

337338
auto uninstall_cmd =
@@ -395,7 +396,7 @@ void CommandLineParser::SetupSystemCommands() {
395396

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

407-
install_engine_cmd->callback([engine_name, &version] {
408+
install_engine_cmd->add_option("-s, --source", src,
409+
"Install engine by local path");
410+
411+
install_engine_cmd->callback([engine_name, &version, &src] {
408412
try {
409-
commands::EngineInstallCmd().Exec(engine_name, version);
413+
commands::EngineInstallCmd().Exec(engine_name, version, src);
410414
} catch (const std::exception& e) {
411415
CTL_ERR(e.what());
412416
}

engine/controllers/command_line_parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CommandLineParser {
2121
void SetupSystemCommands();
2222

2323
void EngineInstall(CLI::App* parent, const std::string& engine_name,
24-
std::string& version);
24+
std::string& version, std::string& src);
2525

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

@@ -35,6 +35,7 @@ class CommandLineParser {
3535
std::string model_alias;
3636
std::string model_path;
3737
std::string engine_version = "latest";
38+
std::string engine_src;
3839
std::string cortex_version;
3940
bool check_upd = true;
4041
int port;

engine/controllers/engines.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void Engines::InstallEngine(
3838
auto jsonResponse = json::parse(res->body);
3939
auto assets = jsonResponse["assets"];
4040

41-
auto os_arch{system_info.os + "-" + system_info.arch};
41+
auto os_arch{system_info->os + "-" + system_info->arch};
4242
for (auto& asset : assets) {
4343
auto assetName = asset["name"].get<std::string>();
4444
if (assetName.find(os_arch) != std::string::npos) {

engine/e2e-test/test_cli_engine_install.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import platform
2+
import tempfile
23

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

40+
def test_engines_should_fallback_to_download_llamacpp_engine_if_not_exists(self):
41+
exit_code, output, error = run(
42+
"Install Engine", ["engines", "install", "cortex.llamacpp", "-s", tempfile.gettempdir()], timeout=None
43+
)
44+
assert "Start downloading" in output, "Should display downloading message"
45+
assert exit_code == 0, f"Install engine failed with error: {error}"
46+
47+
def test_engines_should_not_perform_with_dummy_path(self):
48+
exit_code, output, error = run(
49+
"Install Engine", ["engines", "install", "cortex.llamacpp", "-s", "abcpod"], timeout=None
50+
)
51+
assert "Folder does not exist" in output, "Should display error"
52+
assert exit_code == 0, f"Install engine failed with error: {error}"

engine/main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ void RunServer() {
8888
int main(int argc, char* argv[]) {
8989
// Stop the program if the system is not supported
9090
auto system_info = system_info_utils::GetSystemInfo();
91-
if (system_info.arch == system_info_utils::kUnsupported ||
92-
system_info.os == system_info_utils::kUnsupported) {
93-
CTL_ERR("Unsupported OS or architecture: " << system_info.os << ", "
94-
<< system_info.arch);
91+
if (system_info->arch == system_info_utils::kUnsupported ||
92+
system_info->os == system_info_utils::kUnsupported) {
93+
CTL_ERR("Unsupported OS or architecture: " << system_info->os << ", "
94+
<< system_info->arch);
9595
return 1;
9696
}
9797

0 commit comments

Comments
 (0)