Skip to content

Commit

Permalink
fix: download recursive (#1838)
Browse files Browse the repository at this point in the history
* fix: download recursive

* fix: handle model not loaded

* fix: set permission for all venv folder

* format code
  • Loading branch information
nguyenhoangthuan99 authored Jan 4, 2025
1 parent c893b4b commit a77cd96
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
24 changes: 24 additions & 0 deletions engine/extensions/python-engine/python_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down
7 changes: 1 addition & 6 deletions engine/services/model_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 6 additions & 2 deletions engine/utils/curl_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ cpp::result<Json::Value, std::string> 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()) {
Expand Down

0 comments on commit a77cd96

Please sign in to comment.