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

Commit f738363

Browse files
committed
check latest llamacpp when start
1 parent 6b4f9a5 commit f738363

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

engine/cli/main.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,26 @@ int main(int argc, char* argv[]) {
101101

102102
RemoveBinaryTempFileIfExists();
103103

104+
std::thread t1([]() {
105+
try {
106+
107+
auto get_latest_llamacpp_version = []() {
108+
auto res = github_release_utils::GetReleaseByVersion(
109+
"janhq", "cortex.llamacpp", "latest");
110+
if (res.has_error()) {
111+
CTL_ERR("Failed to get latest llama.cpp version: " << res.error());
112+
return;
113+
}
114+
CTL_INF("Latest llamacpp version: " << res->tag_name);
115+
};
116+
117+
get_latest_llamacpp_version();
118+
} catch (const std::exception& e) {
119+
CTL_ERR("Failed to get latest llama.cpp version: " << e.what());
120+
}
121+
});
122+
t1.detach();
123+
104124
trantor::FileLogger async_file_logger;
105125
SetupLogger(async_file_logger, verbose);
106126

engine/utils/curl_utils.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ size_t WriteCallback(void* contents, size_t size, size_t nmemb,
2525
inline std::optional<std::unordered_map<std::string, std::string>> GetHeaders(
2626
const std::string& url);
2727

28-
inline cpp::result<std::string, std::string> SimpleGet(const std::string& url) {
28+
inline cpp::result<std::string, std::string> SimpleGet(const std::string& url,
29+
const int timeout = -1) {
2930
// Initialize libcurl
3031
curl_global_init(CURL_GLOBAL_DEFAULT);
3132
auto curl = curl_easy_init();
@@ -50,6 +51,9 @@ inline cpp::result<std::string, std::string> SimpleGet(const std::string& url) {
5051
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
5152
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
5253
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
54+
if (timeout > 0) {
55+
curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
56+
}
5357

5458
// Perform the request
5559
auto res = curl_easy_perform(curl);
@@ -242,9 +246,14 @@ inline cpp::result<YAML::Node, std::string> ReadRemoteYaml(
242246
}
243247
}
244248

249+
/**
250+
* SimpleGetJson is a helper function that sends a GET request to the given URL
251+
*
252+
* [timeout] is an optional parameter that specifies the timeout for the request. In second.
253+
*/
245254
inline cpp::result<Json::Value, std::string> SimpleGetJson(
246-
const std::string& url) {
247-
auto result = SimpleGet(url);
255+
const std::string& url, const int timeout = -1) {
256+
auto result = SimpleGet(url, timeout);
248257
if (result.has_error()) {
249258
CTL_ERR("Failed to get JSON from " + url + ": " + result.error());
250259
return cpp::fail(result.error());

engine/utils/engine_constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ constexpr auto static kWindowsOs = "windows";
2424
constexpr auto static kMacOs = "mac";
2525
constexpr auto static kLinuxOs = "linux";
2626
constexpr auto static kUnsupportedOs = "Unsupported OS";
27+
28+
constexpr auto static kCurlGetTimeout = 10;

engine/utils/github_release_utils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <json/value.h>
44
#include "utils/curl_utils.h"
5+
#include "utils/engine_constants.h"
56
#include "utils/engine_matcher_utils.h"
67
#include "utils/result.hpp"
78
#include "utils/url_parser.h"
@@ -193,7 +194,8 @@ inline cpp::result<GitHubRelease, std::string> GetReleaseByVersion(
193194
};
194195

195196
CTL_INF("GetReleaseByVersion: " << url.ToFullPath());
196-
auto result = curl_utils::SimpleGetJson(url_parser::FromUrl(url));
197+
auto result =
198+
curl_utils::SimpleGetJson(url_parser::FromUrl(url), kCurlGetTimeout);
197199

198200
if (result.has_error()) {
199201
return cpp::fail(result.error());

0 commit comments

Comments
 (0)