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

fix: pull issue #1381

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
fix: pull issue
vansangpfiev committed Oct 1, 2024
commit cf26dd7c52a2d2004bcde48f682bafe31b15e738
2 changes: 1 addition & 1 deletion engine/commands/engine_install_cmd.cc
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ void EngineInstallCmd::Exec(const std::string& engine,
auto result = engine_service_.InstallEngine(engine, version, src);
if (result.has_error()) {
CLI_LOG(result.error());
} else {
} else if(result && result.value()){
CLI_LOG("Engine " << engine << " installed successfully!");
}
}
20 changes: 11 additions & 9 deletions engine/services/download_service.cc
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ cpp::result<void, std::string> DownloadService::VerifyDownloadTask(
return {};
}

cpp::result<void, std::string> DownloadService::AddDownloadTask(
cpp::result<bool, std::string> DownloadService::AddDownloadTask(
DownloadTask& task,
std::optional<OnDownloadTaskSuccessfully> callback) noexcept {
auto validating_result = VerifyDownloadTask(task);
@@ -65,12 +65,15 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
// if any item from the task failed to download, the whole task will be
// considered failed
std::optional<std::string> dl_err_msg = std::nullopt;
bool has_task_done = false;
for (const auto& item : task.items) {
CLI_LOG("Start downloading: " + item.localPath.filename().string());
auto result = Download(task.id, item, true);
if (result.has_error()) {
dl_err_msg = result.error();
break;
} else if(result) {
has_task_done |= result.value();
}
}
if (dl_err_msg.has_value()) {
@@ -81,7 +84,7 @@ cpp::result<void, std::string> DownloadService::AddDownloadTask(
if (callback.has_value()) {
callback.value()(task);
}
return {};
return has_task_done;
}

cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
@@ -109,7 +112,7 @@ cpp::result<uint64_t, std::string> DownloadService::GetFileSize(
return content_length;
}

cpp::result<void, std::string> DownloadService::AddAsyncDownloadTask(
cpp::result<bool, std::string> DownloadService::AddAsyncDownloadTask(
DownloadTask& task,
std::optional<OnDownloadTaskSuccessfully> callback) noexcept {
auto verifying_result = VerifyDownloadTask(task);
@@ -142,10 +145,10 @@ cpp::result<void, std::string> DownloadService::AddAsyncDownloadTask(
std::thread t(execute_download_async);
t.detach();

return {};
return true;
}

cpp::result<void, std::string> DownloadService::Download(
cpp::result<bool, std::string> DownloadService::Download(
const std::string& download_id, const DownloadItem& download_item,
bool allow_resume) noexcept {
CTL_INF("Absolute file output: " << download_item.localPath.string());
@@ -182,8 +185,7 @@ cpp::result<void, std::string> DownloadService::Download(
mode = "ab";
CLI_LOG("Resuming download..");
} else {
CLI_LOG("Start over..");
return cpp::fail("Cancelled Resume download!");
CLI_LOG("Start over..");
}
} else {
CLI_LOG(download_item.localPath.filename().string()
@@ -195,7 +197,7 @@ cpp::result<void, std::string> DownloadService::Download(
if (answer == "Y" || answer == "y" || answer.empty()) {
CLI_LOG("Re-downloading..");
} else {
return cpp::fail("Cancelled Re-download!");
return false;
}
}
}
@@ -232,7 +234,7 @@ cpp::result<void, std::string> DownloadService::Download(

fclose(file);
curl_easy_cleanup(curl);
return {};
return true;
}

curl_off_t DownloadService::GetLocalFileSize(
6 changes: 3 additions & 3 deletions engine/services/download_service.h
Original file line number Diff line number Diff line change
@@ -57,11 +57,11 @@ class DownloadService {
using OnDownloadTaskSuccessfully =
std::function<void(const DownloadTask& task)>;

cpp::result<void, std::string> AddDownloadTask(
cpp::result<bool, std::string> AddDownloadTask(
DownloadTask& task, std::optional<OnDownloadTaskSuccessfully> callback =
std::nullopt) noexcept;

cpp::result<void, std::string> AddAsyncDownloadTask(
cpp::result<bool, std::string> AddAsyncDownloadTask(
DownloadTask& task, std::optional<OnDownloadTaskSuccessfully> callback =
std::nullopt) noexcept;

@@ -77,7 +77,7 @@ class DownloadService {
cpp::result<void, std::string> VerifyDownloadTask(
DownloadTask& task) const noexcept;

cpp::result<void, std::string> Download(
cpp::result<bool, std::string> Download(
const std::string& download_id, const DownloadItem& download_item,
bool allow_resume) noexcept;

20 changes: 10 additions & 10 deletions engine/services/engine_service.cc
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ std::vector<EngineInfo> EngineService::GetEngineInfoList() const {
return engines;
}

cpp::result<void, std::string> EngineService::InstallEngine(
cpp::result<bool, std::string> EngineService::InstallEngine(
const std::string& engine, const std::string& version,
const std::string& src) {

@@ -131,7 +131,7 @@ cpp::result<void, std::string> EngineService::InstallEngine(
}
}

cpp::result<void, std::string> EngineService::UnzipEngine(
cpp::result<bool, std::string> EngineService::UnzipEngine(
const std::string& engine, const std::string& version,
const std::string& path) {
bool found_cuda = false;
@@ -193,10 +193,10 @@ cpp::result<void, std::string> EngineService::UnzipEngine(
return DownloadCuda(engine);
}

return {};
return true;
}

cpp::result<void, std::string> EngineService::UninstallEngine(
cpp::result<bool, std::string> EngineService::UninstallEngine(
const std::string& engine) {
auto ecp = file_manager_utils::GetEnginesContainerPath();
auto engine_path = ecp / engine;
@@ -208,14 +208,14 @@ cpp::result<void, std::string> EngineService::UninstallEngine(
try {
std::filesystem::remove_all(engine_path);
CTL_INF("Engine " << engine << " uninstalled successfully!");
return {};
return true;
} catch (const std::exception& e) {
CTL_ERR("Failed to uninstall engine " << engine << ": " << e.what());
return cpp::fail("Failed to uninstall engine " + engine + ": " + e.what());
}
}

cpp::result<void, std::string> EngineService::DownloadEngine(
cpp::result<bool, std::string> EngineService::DownloadEngine(
const std::string& engine, const std::string& version) {
auto get_params = [&engine, &version]() -> std::vector<std::string> {
if (version == "latest") {
@@ -322,22 +322,22 @@ cpp::result<void, std::string> EngineService::DownloadEngine(
});
}
}
return {};
return true;
} else {
return cpp::fail("Failed to fetch engine release: " + engine);
}
}

cpp::result<void, std::string> EngineService::DownloadCuda(
cpp::result<bool, std::string> EngineService::DownloadCuda(
const std::string& engine) {
if (hw_inf_.sys_inf->os == "mac" || engine == "cortex.onnx") {
// mac and onnx engine does not require cuda toolkit
return {};
return true;
}

if (hw_inf_.cuda_driver_version.empty()) {
CTL_WRN("No cuda driver, continue with CPU");
return {};
return true;
}
// download cuda toolkit
const std::string jan_host = "catalog.jan.ai";
10 changes: 5 additions & 5 deletions engine/services/engine_service.h
Original file line number Diff line number Diff line change
@@ -38,21 +38,21 @@ class EngineService {

std::vector<EngineInfo> GetEngineInfoList() const;

cpp::result<void, std::string> InstallEngine(
cpp::result<bool, std::string> InstallEngine(
const std::string& engine, const std::string& version = "latest",
const std::string& src = "");

cpp::result<void, std::string> UninstallEngine(const std::string& engine);
cpp::result<bool, std::string> UninstallEngine(const std::string& engine);

private:
cpp::result<void, std::string> UnzipEngine(const std::string& engine,
cpp::result<bool, std::string> UnzipEngine(const std::string& engine,
const std::string& version,
const std::string& path);

cpp::result<void, std::string> DownloadEngine(
cpp::result<bool, std::string> DownloadEngine(
const std::string& engine, const std::string& version = "latest");

cpp::result<void, std::string> DownloadCuda(const std::string& engine);
cpp::result<bool, std::string> DownloadCuda(const std::string& engine);

std::string GetMatchedVariant(const std::string& engine,
const std::vector<std::string>& variants);
8 changes: 4 additions & 4 deletions engine/services/model_service.cc
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ cpp::result<std::string, std::string> ModelService::HandleUrl(
if (result.has_error()) {
// CTL_ERR(result.error());
return cpp::fail(result.error());
} else {
} else if (result && result.value()) {
CLI_LOG("Model " << model_id << " downloaded successfully!")
}
return unique_model_id;
@@ -295,7 +295,7 @@ cpp::result<std::string, std::string> ModelService::DownloadModelFromCortexso(

if (result.has_error()) {
return cpp::fail(result.error());
} else {
} else if (result && result.value()) {
CLI_LOG("Model " << model_id << " downloaded successfully!")
}

@@ -415,7 +415,7 @@ cpp::result<bool, std::string> ModelService::StartModel(
auto res = cli.Post("/inferences/server/loadmodel", httplib::Headers(),
data_str.data(), data_str.size(), "application/json");
if (res) {
if (res->status == httplib::StatusCode::OK_200) {
if (res->status == httplib::StatusCode::OK_200) {
return true;
} else {
CTL_ERR("Model failed to load with status code: " << res->status);
@@ -459,7 +459,7 @@ cpp::result<bool, std::string> ModelService::StopModel(
auto res = cli.Post("/inferences/server/unloadmodel", httplib::Headers(),
data_str.data(), data_str.size(), "application/json");
if (res) {
if (res->status == httplib::StatusCode::OK_200) {
if (res->status == httplib::StatusCode::OK_200) {
return true;
} else {
CTL_ERR("Model failed to unload with status code: " << res->status);