From 30d19fe9df7e5f2fc1e6484521c4a525e58de117 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 10 Sep 2024 00:00:39 +0700 Subject: [PATCH] update --- engine/commands/cortex_upd_cmd.cc | 17 ++++------------- engine/controllers/command_line_parser.cc | 4 ++-- engine/controllers/engines.cc | 12 +++--------- engine/services/download_service.cc | 8 ++------ engine/services/download_service.h | 7 +------ engine/utils/cortexso_parser.h | 16 +++++++--------- 6 files changed, 19 insertions(+), 45 deletions(-) diff --git a/engine/commands/cortex_upd_cmd.cc b/engine/commands/cortex_upd_cmd.cc index 9027203e7..027439b4d 100644 --- a/engine/commands/cortex_upd_cmd.cc +++ b/engine/commands/cortex_upd_cmd.cc @@ -1,6 +1,3 @@ -// clang-format off -#include "utils/cortex_utils.h" -// clang-format on #include "cortex_upd_cmd.h" #include "httplib.h" #include "nlohmann/json.hpp" @@ -66,23 +63,17 @@ void CortexUpdCmd::Exec(std::string v) { for (auto& asset : assets) { auto asset_name = asset["name"].get(); if (asset_name == matched_variant) { - std::string host{"https://github.com"}; - auto full_url = asset["browser_download_url"].get(); - std::string path = full_url.substr(host.length()); - - auto fileName = asset["name"].get(); + auto file_name = asset["name"].get(); CTL_INF("URL: " << full_url); auto download_task = DownloadTask{.id = "cortex", .type = DownloadType::Cortex, - .error = std::nullopt, .items = {DownloadItem{ .id = "cortex", - .host = host, - .fileName = fileName, + .fileName = file_name, .type = DownloadType::Cortex, - .path = path, + .path = full_url, }}}; DownloadService download_service; @@ -168,4 +159,4 @@ void CortexUpdCmd::Exec(std::string v) { #endif CLI_LOG("Update cortex sucessfully"); } -} // namespace commands \ No newline at end of file +} // namespace commands diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 0c8f3e26e..d461c727b 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -241,7 +241,7 @@ void CommandLineParser::EngineInstall(CLI::App* parent, std::string& version) { auto install_engine_cmd = parent->add_subcommand(engine_name, ""); - install_engine_cmd->callback([&] { + install_engine_cmd->callback([=] { commands::EngineInitCmd eic(engine_name, version); eic.Exec(); }); @@ -251,7 +251,7 @@ void CommandLineParser::EngineUninstall(CLI::App* parent, const std::string& engine_name) { auto uninstall_engine_cmd = parent->add_subcommand(engine_name, ""); - uninstall_engine_cmd->callback([&] { + uninstall_engine_cmd->callback([=] { commands::EngineUninstallCmd cmd(engine_name); cmd.Exec(); }); diff --git a/engine/controllers/engines.cc b/engine/controllers/engines.cc index dd7ba3036..04660b85f 100644 --- a/engine/controllers/engines.cc +++ b/engine/controllers/engines.cc @@ -54,23 +54,17 @@ void Engines::InstallEngine( for (auto& asset : assets) { auto assetName = asset["name"].get(); if (assetName.find(os_arch) != std::string::npos) { - std::string host{"https://github.com"}; - auto full_url = asset["browser_download_url"].get(); - std::string path = full_url.substr(host.length()); - - auto fileName = asset["name"].get(); + auto name = asset["name"].get(); LOG_INFO << "URL: " << full_url; auto downloadTask = DownloadTask{.id = engine, .type = DownloadType::Engine, - .error = std::nullopt, .items = {DownloadItem{ .id = engine, - .host = host, - .fileName = fileName, + .fileName = name, .type = DownloadType::Engine, - .path = path, + .path = full_url, }}}; DownloadService().AddAsyncDownloadTask( diff --git a/engine/services/download_service.cc b/engine/services/download_service.cc index e1a551e9f..03d23d363 100644 --- a/engine/services/download_service.cc +++ b/engine/services/download_service.cc @@ -16,9 +16,7 @@ void DownloadService::AddDownloadTask(const DownloadTask& task, for (const auto& item : task.items) { try { - auto download_url{item.host + "/" + item.path}; - auto file_size = GetFileSize(download_url); - + auto file_size = GetFileSize(item.path); std::cout << "file name: " << item.fileName << std::endl; std::cout << "file size: " << file_size << std::endl; } catch (const std::runtime_error& e) { @@ -114,8 +112,6 @@ void DownloadService::Download( size_t (*progressCallbackPtr)(void*, curl_off_t, curl_off_t, curl_off_t, curl_off_t) = &ProgressCallback; - auto downloadUrl{download_item.host + "/" + download_item.path}; - CTL_INF("download ulr" << downloadUrl.c_str()); curl = curl_easy_init(); if (!curl) { // TODO: throw a custom exception @@ -127,7 +123,7 @@ void DownloadService::Download( throw std::runtime_error("Failed to open output file"); } - curl_easy_setopt(curl, CURLOPT_URL, downloadUrl.c_str()); + curl_easy_setopt(curl, CURLOPT_URL, download_item.path.c_str()); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallbackPtr); curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progressCallbackPtr); diff --git a/engine/services/download_service.h b/engine/services/download_service.h index cdb317c03..4c8c78e11 100644 --- a/engine/services/download_service.h +++ b/engine/services/download_service.h @@ -16,9 +16,6 @@ enum class DownloadStatus { struct DownloadItem { std::string id; - // not needed anymore if we using libcurl to download - std::string host; - std::string fileName; DownloadType type; @@ -33,13 +30,11 @@ struct DownloadItem { struct DownloadTask { std::string id; DownloadType type; - std::optional error; std::vector items; std::string ToString() const { return "DownloadTask{id: " + id + - ", type: " + std::to_string(static_cast(type)) + - ", error: " + (error.has_value() ? error.value() : "nullopt") + "}"; + ", type: " + std::to_string(static_cast(type)) + "}"; } }; diff --git a/engine/utils/cortexso_parser.h b/engine/utils/cortexso_parser.h index 91efa1fff..7167da889 100644 --- a/engine/utils/cortexso_parser.h +++ b/engine/utils/cortexso_parser.h @@ -31,24 +31,22 @@ inline std::optional getDownloadTask( for (auto& [key, value] : jsonResponse.items()) { std::ostringstream downloadUrlOutput; auto path = value["path"].get(); - downloadUrlOutput << repoAndModelIdStr << "/resolve/" << branch << "/" - << path; + downloadUrlOutput << kHuggingFaceHost << "/" << repoAndModelIdStr + << "/resolve/" << branch << "/" << path; const std::string downloadUrl = downloadUrlOutput.str(); DownloadItem downloadItem{}; downloadItem.id = path; - downloadItem.host = kHuggingFaceHost; downloadItem.fileName = path; downloadItem.type = DownloadType::Model; downloadItem.path = downloadUrl; downloadItems.push_back(downloadItem); } - DownloadTask downloadTask{}; - downloadTask.id = branch == "main" ? modelId : modelId + "-" + branch; - downloadTask.type = DownloadType::Model; - downloadTask.error = std::nullopt; - downloadTask.items = downloadItems; + DownloadTask downloadTask{ + .id = branch == "main" ? modelId : modelId + "-" + branch, + .type = DownloadType::Model, + .items = downloadItems}; return downloadTask; } catch (const json::parse_error& e) { @@ -61,4 +59,4 @@ inline std::optional getDownloadTask( } return std::nullopt; } -} // namespace cortexso_parser \ No newline at end of file +} // namespace cortexso_parser