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

Commit a152a1a

Browse files
authored
feat: download pre-release engine (#1237)
* feat: download pre-release * feat: download pre-release * chore: add e2e test * fix: m
1 parent 6dcecef commit a152a1a

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

engine/controllers/command_line_parser.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ void CommandLineParser::EngineInstall(CLI::App* parent,
224224
std::string& version) {
225225
auto install_engine_cmd = parent->add_subcommand(engine_name, "");
226226

227-
install_engine_cmd->callback([engine_name, version] {
227+
install_engine_cmd->add_option("-v, --version", version,
228+
"Engine version to download");
229+
230+
install_engine_cmd->callback([engine_name, &version] {
228231
try {
229232
commands::EngineInstallCmd().Exec(engine_name, version);
230233
} catch (const std::exception& e) {

engine/e2e-test/test_cli_engine_install.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ def test_engines_install_onnx_on_tensorrt_should_be_failed(self):
2828
)
2929
assert "No variant found" in output, "Should display error message"
3030
assert exit_code == 0, f"Install engine failed with error: {error}"
31+
32+
def test_engines_install_pre_release_llamacpp(self):
33+
exit_code, output, error = run(
34+
"Install Engine", ["engines", "install", "cortex.llamacpp", "-v", "v0.1.29"], timeout=60
35+
)
36+
assert "Start downloading" in output, "Should display downloading message"
37+
assert exit_code == 0, f"Install engine failed with error: {error}"
38+

engine/main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ int main(int argc, char* argv[]) {
206206
verbose = true;
207207
}
208208
}
209+
210+
trantor::FileLogger asyncFileLogger;
209211
if (!verbose) {
210212
auto config = file_manager_utils::GetCortexConfig();
211213
std::filesystem::create_directories(
212214
std::filesystem::path(config.logFolderPath) /
213215
std::filesystem::path(cortex_utils::logs_folder));
214-
trantor::FileLogger asyncFileLogger;
215216
asyncFileLogger.setFileName(config.logFolderPath + "/" +
216217
cortex_utils::logs_cli_base_name);
217218
asyncFileLogger.setMaxLines(

engine/services/engine_service.cc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,42 @@ std::vector<EngineInfo> EngineService::GetEngineInfoList() const {
7676
void EngineService::InstallEngine(const std::string& engine,
7777
const std::string& version) {
7878
auto system_info = system_info_utils::GetSystemInfo();
79+
auto get_params = [&engine, &version]() -> std::vector<std::string> {
80+
if (version == "latest") {
81+
return {"repos", "janhq", engine, "releases", version};
82+
} else {
83+
return {"repos", "janhq", engine, "releases"};
84+
}
85+
};
86+
7987
auto url_obj = url_parser::Url{
8088
.protocol = "https",
8189
.host = "api.github.com",
82-
.pathParams = {"repos", "janhq", engine, "releases", version},
90+
.pathParams = get_params(),
8391
};
8492

8593
httplib::Client cli(url_obj.GetProtocolAndHost());
8694
if (auto res = cli.Get(url_obj.GetPathAndQuery());
8795
res->status == httplib::StatusCode::OK_200) {
8896
auto body = json::parse(res->body);
97+
auto get_data =
98+
[&version](const nlohmann::json& json_data) -> nlohmann::json {
99+
for (auto& jr : json_data) {
100+
// Get the latest or match version
101+
if (auto tag = jr["tag_name"].get<std::string>(); tag == version) {
102+
return jr;
103+
}
104+
}
105+
return nlohmann::json();
106+
};
107+
108+
if (version != "latest") {
109+
body = get_data(body);
110+
}
111+
if (body.empty()) {
112+
throw std::runtime_error("No release found for " + version);
113+
}
114+
89115
auto assets = body["assets"];
90116
auto os_arch{system_info.os + "-" + system_info.arch};
91117

0 commit comments

Comments
 (0)