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: install local engine #1292

Merged
merged 17 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
12 changes: 6 additions & 6 deletions engine/commands/cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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 @@ -56,7 +56,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 All @@ -83,7 +83,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 @@ -113,7 +113,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 @@ -205,11 +205,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
13 changes: 9 additions & 4 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {

// Default version is latest
std::string version{"latest"};
std::string src;
// engines group commands
auto engines_cmd =
app_.add_subcommand("engines", "Subcommands for managing engines");
Expand All @@ -199,7 +200,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
install_cmd->require_subcommand();
for (auto& engine : engine_service_.kSupportEngines) {
std::string engine_name{engine};
EngineInstall(install_cmd, engine_name, version);
EngineInstall(install_cmd, engine_name, version, src);
}

auto uninstall_cmd =
Expand Down Expand Up @@ -282,15 +283,19 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {

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->add_option("-v, --version", version,
"Engine version to download");

install_engine_cmd->add_option("-s, --source", src,
"Download engine by local path or remote url");

install_engine_cmd->callback([engine_name, &version] {
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
2 changes: 1 addition & 1 deletion engine/controllers/command_line_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CommandLineParser {

private:
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 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
Loading