Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
154 changes: 153 additions & 1 deletion docs/static/openapi/jan.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,66 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PullModelResponse"
"type": "object",
"properties": {
"message": {
"type": "string"
},
"task": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"bytes": {
"type": "integer"
},
"checksum": {
"type": "string"
},
"downloadUrl": {
"type": "string"
},
"downloadedBytes": {
"type": "integer"
},
"id": {
"type": "string"
},
"localPath": {
"type": "string"
}
}
}
},
"type": {
"type": "string"
}
}
}
}
},
"example": {
"message": "Model start downloading!",
"task": {
"id": "TheBloke:Mistral-7B-Instruct-v0.1-GGUF:mistral-7b-instruct-v0.1.Q3_K_L.gguf",
"items": [
{
"bytes": 3822024352,
"checksum": "N/A",
"downloadUrl": "https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q3_K_L.gguf",
"downloadedBytes": 0,
"id": "TheBloke:Mistral-7B-Instruct-v0.1-GGUF:mistral-7b-instruct-v0.1.Q3_K_L.gguf",
"localPath": "/Users/jamesnguyen/cortexcpp/models/huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/mistral-7b-instruct-v0.1.Q3_K_L.gguf"
}
],
"type": "Model"
}
}
}
}
Expand All @@ -213,6 +272,99 @@
}
},
"tags": ["Models"]
},
"delete": {
"tags": ["Models"],
"summary": "Stop model download",
"description": "Stops the download of a model with the corresponding taskId provided in the request body",
"operationId": "ModelsController_stopModelDownload",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"taskId": {
"type": "string",
"description": "The unique identifier of the download task to be stopped"
}
},
"required": ["taskId"]
}
}
}
},
"responses": {
"200": {
"description": "Download stopped successfully",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "Download stopped successfully"
},
"taskId": {
"type": "string",
"example": "task-123456"
}
}
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "Invalid taskId"
}
}
}
}
}
},
"404": {
"description": "Task not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "Download task not found"
}
}
}
}
}
},
"500": {
"description": "Internal server error",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "An unexpected error occurred"
}
}
}
}
}
}
}
}
},
"/v1/models": {
Expand Down
3 changes: 2 additions & 1 deletion engine/controllers/models.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void Models::AbortPullModel(
callback(resp);
} else {
Json::Value ret;
ret["message"] = "Task stopped!";
ret["message"] = "Download stopped successfully";
ret["taskId"] = result.value();
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
resp->setStatusCode(k200OK);
callback(resp);
Expand Down
2 changes: 1 addition & 1 deletion engine/controllers/models.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Models : public drogon::HttpController<Models, false> {
METHOD_ADD(Models::GetModelStatus, "/status/{1}", Get);

ADD_METHOD_TO(Models::PullModel, "/v1/models/pull", Post);
ADD_METHOD_TO(Models::PullModel, "/v1/models/pull", Delete);
ADD_METHOD_TO(Models::AbortPullModel, "/v1/models/pull", Delete);
ADD_METHOD_TO(Models::ListModel, "/v1/models", Get);
ADD_METHOD_TO(Models::GetModel, "/v1/models/{1}", Get);
ADD_METHOD_TO(Models::UpdateModel, "/v1/models/{1}", Patch);
Expand Down
7 changes: 4 additions & 3 deletions engine/services/download_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ void DownloadService::ProcessTask(DownloadTask& task) {
downloading_data_.reset();
}

RemoveTaskFromStopList(task.id);

// if terminate by API calling and not from process stopping, we emit
// DownloadStopped event
if (is_terminated) {
Expand All @@ -314,7 +316,6 @@ void DownloadService::ProcessTask(DownloadTask& task) {
DownloadEvent{.type_ = DownloadEventType::DownloadStopped,
.download_task_ = task});
} else {
RemoveTaskFromStopList(task.id);
CTL_INF("Executing callback..");
ExecuteCallback(task);

Expand All @@ -325,13 +326,13 @@ void DownloadService::ProcessTask(DownloadTask& task) {
}
}

cpp::result<void, std::string> DownloadService::StopTask(
cpp::result<std::string, std::string> DownloadService::StopTask(
const std::string& task_id) {
std::lock_guard<std::mutex> lock(stop_mutex_);

tasks_to_stop_.insert(task_id);
CTL_INF("Added task to stop list: " << task_id);
return {};
return task_id;
}

void DownloadService::ProcessCompletedTransfers() {
Expand Down
2 changes: 1 addition & 1 deletion engine/services/download_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DownloadService {
cpp::result<uint64_t, std::string> GetFileSize(
const std::string& url) const noexcept;

cpp::result<void, std::string> StopTask(const std::string& task_id);
cpp::result<std::string, std::string> StopTask(const std::string& task_id);

private:
struct DownloadingData {
Expand Down
5 changes: 2 additions & 3 deletions engine/services/model_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,7 @@ cpp::result<bool, std::string> ModelService::GetModelStatus(
}
}

cpp::result<void, std::string> ModelService::AbortDownloadModel(
cpp::result<std::string, std::string> ModelService::AbortDownloadModel(
const std::string& task_id) {
auto result = download_service_->StopTask(task_id);
return result;
return download_service_->StopTask(task_id);
}
3 changes: 2 additions & 1 deletion engine/services/model_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ModelService {
*/
cpp::result<std::string, std::string> DownloadModel(const std::string& input);

cpp::result<void, std::string> AbortDownloadModel(const std::string& task_id);
cpp::result<std::string, std::string> AbortDownloadModel(
const std::string& task_id);

cpp::result<std::string, std::string> DownloadModelFromCortexso(
const std::string& name, const std::string& branch = "main");
Expand Down
Loading