Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 2e63d38

Browse files
authored
Merge pull request #1501 from janhq/j/update-v1-path-abort-download
fix: map v1 path for abort download model
2 parents 6f22aa1 + c220312 commit 2e63d38

File tree

7 files changed

+165
-11
lines changed

7 files changed

+165
-11
lines changed

docs/static/openapi/jan.json

Lines changed: 153 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,66 @@
196196
"content": {
197197
"application/json": {
198198
"schema": {
199-
"$ref": "#/components/schemas/PullModelResponse"
199+
"type": "object",
200+
"properties": {
201+
"message": {
202+
"type": "string"
203+
},
204+
"task": {
205+
"type": "object",
206+
"properties": {
207+
"id": {
208+
"type": "string"
209+
},
210+
"items": {
211+
"type": "array",
212+
"items": {
213+
"type": "object",
214+
"properties": {
215+
"bytes": {
216+
"type": "integer"
217+
},
218+
"checksum": {
219+
"type": "string"
220+
},
221+
"downloadUrl": {
222+
"type": "string"
223+
},
224+
"downloadedBytes": {
225+
"type": "integer"
226+
},
227+
"id": {
228+
"type": "string"
229+
},
230+
"localPath": {
231+
"type": "string"
232+
}
233+
}
234+
}
235+
},
236+
"type": {
237+
"type": "string"
238+
}
239+
}
240+
}
241+
}
242+
},
243+
"example": {
244+
"message": "Model start downloading!",
245+
"task": {
246+
"id": "TheBloke:Mistral-7B-Instruct-v0.1-GGUF:mistral-7b-instruct-v0.1.Q3_K_L.gguf",
247+
"items": [
248+
{
249+
"bytes": 3822024352,
250+
"checksum": "N/A",
251+
"downloadUrl": "https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q3_K_L.gguf",
252+
"downloadedBytes": 0,
253+
"id": "TheBloke:Mistral-7B-Instruct-v0.1-GGUF:mistral-7b-instruct-v0.1.Q3_K_L.gguf",
254+
"localPath": "/Users/jamesnguyen/cortexcpp/models/huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/mistral-7b-instruct-v0.1.Q3_K_L.gguf"
255+
}
256+
],
257+
"type": "Model"
258+
}
200259
}
201260
}
202261
}
@@ -213,6 +272,99 @@
213272
}
214273
},
215274
"tags": ["Models"]
275+
},
276+
"delete": {
277+
"tags": ["Models"],
278+
"summary": "Stop model download",
279+
"description": "Stops the download of a model with the corresponding taskId provided in the request body",
280+
"operationId": "ModelsController_stopModelDownload",
281+
"requestBody": {
282+
"required": true,
283+
"content": {
284+
"application/json": {
285+
"schema": {
286+
"type": "object",
287+
"properties": {
288+
"taskId": {
289+
"type": "string",
290+
"description": "The unique identifier of the download task to be stopped"
291+
}
292+
},
293+
"required": ["taskId"]
294+
}
295+
}
296+
}
297+
},
298+
"responses": {
299+
"200": {
300+
"description": "Download stopped successfully",
301+
"content": {
302+
"application/json": {
303+
"schema": {
304+
"type": "object",
305+
"properties": {
306+
"message": {
307+
"type": "string",
308+
"example": "Download stopped successfully"
309+
},
310+
"taskId": {
311+
"type": "string",
312+
"example": "task-123456"
313+
}
314+
}
315+
}
316+
}
317+
}
318+
},
319+
"400": {
320+
"description": "Bad request",
321+
"content": {
322+
"application/json": {
323+
"schema": {
324+
"type": "object",
325+
"properties": {
326+
"error": {
327+
"type": "string",
328+
"example": "Invalid taskId"
329+
}
330+
}
331+
}
332+
}
333+
}
334+
},
335+
"404": {
336+
"description": "Task not found",
337+
"content": {
338+
"application/json": {
339+
"schema": {
340+
"type": "object",
341+
"properties": {
342+
"error": {
343+
"type": "string",
344+
"example": "Download task not found"
345+
}
346+
}
347+
}
348+
}
349+
}
350+
},
351+
"500": {
352+
"description": "Internal server error",
353+
"content": {
354+
"application/json": {
355+
"schema": {
356+
"type": "object",
357+
"properties": {
358+
"error": {
359+
"type": "string",
360+
"example": "An unexpected error occurred"
361+
}
362+
}
363+
}
364+
}
365+
}
366+
}
367+
}
216368
}
217369
},
218370
"/v1/models": {

engine/controllers/models.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void Models::AbortPullModel(
8282
callback(resp);
8383
} else {
8484
Json::Value ret;
85-
ret["message"] = "Task stopped!";
85+
ret["message"] = "Download stopped successfully";
86+
ret["taskId"] = result.value();
8687
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
8788
resp->setStatusCode(k200OK);
8889
callback(resp);

engine/controllers/models.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Models : public drogon::HttpController<Models, false> {
2222
METHOD_ADD(Models::GetModelStatus, "/status/{1}", Get);
2323

2424
ADD_METHOD_TO(Models::PullModel, "/v1/models/pull", Post);
25-
ADD_METHOD_TO(Models::PullModel, "/v1/models/pull", Delete);
25+
ADD_METHOD_TO(Models::AbortPullModel, "/v1/models/pull", Delete);
2626
ADD_METHOD_TO(Models::ListModel, "/v1/models", Get);
2727
ADD_METHOD_TO(Models::GetModel, "/v1/models/{1}", Get);
2828
ADD_METHOD_TO(Models::UpdateModel, "/v1/models/{1}", Patch);

engine/services/download_service.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ void DownloadService::ProcessTask(DownloadTask& task) {
306306
downloading_data_.reset();
307307
}
308308

309+
RemoveTaskFromStopList(task.id);
310+
309311
// if terminate by API calling and not from process stopping, we emit
310312
// DownloadStopped event
311313
if (is_terminated) {
@@ -314,7 +316,6 @@ void DownloadService::ProcessTask(DownloadTask& task) {
314316
DownloadEvent{.type_ = DownloadEventType::DownloadStopped,
315317
.download_task_ = task});
316318
} else {
317-
RemoveTaskFromStopList(task.id);
318319
CTL_INF("Executing callback..");
319320
ExecuteCallback(task);
320321

@@ -325,13 +326,13 @@ void DownloadService::ProcessTask(DownloadTask& task) {
325326
}
326327
}
327328

328-
cpp::result<void, std::string> DownloadService::StopTask(
329+
cpp::result<std::string, std::string> DownloadService::StopTask(
329330
const std::string& task_id) {
330331
std::lock_guard<std::mutex> lock(stop_mutex_);
331332

332333
tasks_to_stop_.insert(task_id);
333334
CTL_INF("Added task to stop list: " << task_id);
334-
return {};
335+
return task_id;
335336
}
336337

337338
void DownloadService::ProcessCompletedTransfers() {

engine/services/download_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class DownloadService {
7575
cpp::result<uint64_t, std::string> GetFileSize(
7676
const std::string& url) const noexcept;
7777

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

8080
private:
8181
struct DownloadingData {

engine/services/model_service.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ cpp::result<bool, std::string> ModelService::GetModelStatus(
718718
}
719719
}
720720

721-
cpp::result<void, std::string> ModelService::AbortDownloadModel(
721+
cpp::result<std::string, std::string> ModelService::AbortDownloadModel(
722722
const std::string& task_id) {
723-
auto result = download_service_->StopTask(task_id);
724-
return result;
723+
return download_service_->StopTask(task_id);
725724
}

engine/services/model_service.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class ModelService {
1717
*/
1818
cpp::result<std::string, std::string> DownloadModel(const std::string& input);
1919

20-
cpp::result<void, std::string> AbortDownloadModel(const std::string& task_id);
20+
cpp::result<std::string, std::string> AbortDownloadModel(
21+
const std::string& task_id);
2122

2223
cpp::result<std::string, std::string> DownloadModelFromCortexso(
2324
const std::string& name, const std::string& branch = "main");

0 commit comments

Comments
 (0)