Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ void CommandLineParser::EngineInstall(CLI::App* parent,
std::string& version) {
auto install_engine_cmd = parent->add_subcommand(engine_name, "");

install_engine_cmd->callback([engine_name, version] {
install_engine_cmd->add_option("-v, --version", version,
"Engine version to download");

install_engine_cmd->callback([engine_name, &version] {
try {
commands::EngineInstallCmd().Exec(engine_name, version);
} catch (const std::exception& e) {
Expand Down
8 changes: 8 additions & 0 deletions engine/e2e-test/test_cli_engine_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ def test_engines_install_onnx_on_tensorrt_should_be_failed(self):
)
assert "No variant found" in output, "Should display error message"
assert exit_code == 0, f"Install engine failed with error: {error}"

def test_engines_install_pre_release_llamacpp(self):
exit_code, output, error = run(
"Install Engine", ["engines", "install", "cortex.llamacpp", "-v", "v0.1.29"], timeout=60
)
assert "Start downloading" in output, "Should display downloading message"
assert exit_code == 0, f"Install engine failed with error: {error}"

3 changes: 2 additions & 1 deletion engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,13 @@ int main(int argc, char* argv[]) {
verbose = true;
}
}

trantor::FileLogger asyncFileLogger;
if (!verbose) {
auto config = file_manager_utils::GetCortexConfig();
std::filesystem::create_directories(
std::filesystem::path(config.logFolderPath) /
std::filesystem::path(cortex_utils::logs_folder));
trantor::FileLogger asyncFileLogger;
asyncFileLogger.setFileName(config.logFolderPath + "/" +
cortex_utils::logs_cli_base_name);
asyncFileLogger.setMaxLines(
Expand Down
28 changes: 27 additions & 1 deletion engine/services/engine_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,42 @@ std::vector<EngineInfo> EngineService::GetEngineInfoList() const {
void EngineService::InstallEngine(const std::string& engine,
const std::string& version) {
auto system_info = system_info_utils::GetSystemInfo();
auto get_params = [&engine, &version]() -> std::vector<std::string> {
if (version == "latest") {
return {"repos", "janhq", engine, "releases", version};
} else {
return {"repos", "janhq", engine, "releases"};
}
};

auto url_obj = url_parser::Url{
.protocol = "https",
.host = "api.github.com",
.pathParams = {"repos", "janhq", engine, "releases", version},
.pathParams = get_params(),
};

httplib::Client cli(url_obj.GetProtocolAndHost());
if (auto res = cli.Get(url_obj.GetPathAndQuery());
res->status == httplib::StatusCode::OK_200) {
auto body = json::parse(res->body);
auto get_data =
[&version](const nlohmann::json& json_data) -> nlohmann::json {
for (auto& jr : json_data) {
// Get the latest or match version
if (auto tag = jr["tag_name"].get<std::string>(); tag == version) {
return jr;
}
}
return nlohmann::json();
};

if (version != "latest") {
body = get_data(body);
}
if (body.empty()) {
throw std::runtime_error("No release found for " + version);
}

auto assets = body["assets"];
auto os_arch{system_info.os + "-" + system_info.arch};

Expand Down