From a77cd969130fc8f1af5dcab93c067fbffaa1cca3 Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 <35255081+nguyenhoangthuan99@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:39:55 +0700 Subject: [PATCH] fix: download recursive (#1838) * fix: download recursive * fix: handle model not loaded * fix: set permission for all venv folder * format code --- .../extensions/python-engine/python_engine.cc | 24 +++++++++++++++++++ engine/services/model_service.cc | 7 +----- engine/utils/curl_utils.cc | 8 +++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/engine/extensions/python-engine/python_engine.cc b/engine/extensions/python-engine/python_engine.cc index 9be369bcf..a62f6526b 100644 --- a/engine/extensions/python-engine/python_engine.cc +++ b/engine/extensions/python-engine/python_engine.cc @@ -531,6 +531,18 @@ void PythonEngine::HandleInference( std::string model = (*json_body)["model"].asString(); Json::Value body = (*json_body)["body"]; + if (models_.find(model) == models_.end()) { + Json::Value error; + error["error"] = "Model '" + model + "' is not loaded!"; + Json::Value status; + status["is_done"] = true; + status["has_error"] = true; + status["is_stream"] = false; + status["status_code"] = k400BadRequest; + callback(std::move(status), std::move(error)); + return; + } + // Transform Request std::string transformed_request; if (!transform_request.empty()) { @@ -699,6 +711,18 @@ void PythonEngine::HandleRouteRequest( std::string model = (*json_body)["model"].asString(); Json::Value body = (*json_body)["body"]; + if (models_.find(model) == models_.end()) { + Json::Value error; + error["error"] = "Model '" + model + "' is not loaded!"; + Json::Value status; + status["is_done"] = true; + status["has_error"] = true; + status["is_stream"] = false; + status["status_code"] = k400BadRequest; + callback(std::move(status), std::move(error)); + return; + } + // Transform Request std::string transformed_request; if (!transform_request.empty()) { diff --git a/engine/services/model_service.cc b/engine/services/model_service.cc index c7925360b..e1d436058 100644 --- a/engine/services/model_service.cc +++ b/engine/services/model_service.cc @@ -582,13 +582,8 @@ ModelService::DownloadModelFromCortexsoAsync( pyvenv_cfg.close(); // Add executable permission to python -#ifdef _WIN32 - set_permission_utils::SetExecutePermissionsRecursive( - venv_path / std::filesystem::path("Scripts")); -#else set_permission_utils::SetExecutePermissionsRecursive( - venv_path / std::filesystem::path("bin")); -#endif + venv_path ); } else { CTL_ERR("Failed to extract venv.zip"); diff --git a/engine/utils/curl_utils.cc b/engine/utils/curl_utils.cc index be82b5cfa..d5945e8c8 100644 --- a/engine/utils/curl_utils.cc +++ b/engine/utils/curl_utils.cc @@ -271,8 +271,12 @@ cpp::result SimpleGetJsonRecursive( if (root.isArray()) { for (const auto& value : root) { if (value["type"].asString() == "directory") { - auto temp = SimpleGetJsonRecursive(url + "/" + value["path"].asString(), - timeout); + auto temp = SimpleGetJsonRecursive( + url + "/" + + std::filesystem::path(value["path"].asString()) + .filename() + .string(), + timeout); if (!temp.has_error()) { if (temp.value().isArray()) { for (const auto& item : temp.value()) {