Skip to content

Commit 7dffb9a

Browse files
authored
Add missing 'ready' status in the ProgressInfo type (#1070)
1 parent c850083 commit 7dffb9a

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

src/utils/core.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,45 @@
99
*/
1010

1111
/**
12-
* @typedef {Object} ProgressInfo
13-
* @property {'initiate' | 'download' | 'progress' | 'done'} status The status of the progress item.
14-
* @property {string} name This can be either:
15-
* - a string, the *model id* of a model repo on huggingface.co.
16-
* - a path to a *directory* potentially containing the file.
17-
* @property {string} file The name of the file
18-
* @property {number} [progress] A number between 0 and 100. Only available for the 'progress' status.
19-
* @property {number} [loaded] The number of bytes loaded. Only available for the 'progress' status.
20-
* @property {number} [total] The total number of bytes to be loaded. Only available for the 'progress' status.
12+
* @typedef {Object} InitiateProgressInfo
13+
* @property {'initiate'} status
14+
* @property {string} name The model id or directory path.
15+
* @property {string} file The name of the file.
16+
*/
17+
18+
/**
19+
* @typedef {Object} DownloadProgressInfo
20+
* @property {'download'} status
21+
* @property {string} name The model id or directory path.
22+
* @property {string} file The name of the file.
23+
*/
24+
25+
/**
26+
* @typedef {Object} ProgressStatusInfo
27+
* @property {'progress'} status
28+
* @property {string} name The model id or directory path.
29+
* @property {string} file The name of the file.
30+
* @property {number} progress A number between 0 and 100.
31+
* @property {number} loaded The number of bytes loaded.
32+
* @property {number} total The total number of bytes to be loaded.
33+
*/
34+
35+
/**
36+
* @typedef {Object} DoneProgressInfo
37+
* @property {'done'} status
38+
* @property {string} name The model id or directory path.
39+
* @property {string} file The name of the file.
40+
*/
41+
42+
/**
43+
* @typedef {Object} ReadyProgressInfo
44+
* @property {'ready'} status
45+
* @property {string} task The loaded task.
46+
* @property {string} model The loaded model.
47+
*/
48+
49+
/**
50+
* @typedef {InitiateProgressInfo | DownloadProgressInfo | ProgressStatusInfo | DoneProgressInfo | ReadyProgressInfo} ProgressInfo
2151
*/
2252

2353
/**

src/utils/hub.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,6 @@ export async function getModelFile(path_or_repo_id, filename, fatal = true, opti
504504
file: filename
505505
})
506506

507-
/** @type {import('./core.js').ProgressInfo} */
508-
const progressInfo = {
509-
status: 'progress',
510-
name: path_or_repo_id,
511-
file: filename
512-
}
513-
514507
/** @type {Uint8Array} */
515508
let buffer;
516509

@@ -530,15 +523,19 @@ export async function getModelFile(path_or_repo_id, filename, fatal = true, opti
530523

531524
// For completeness, we still fire the final progress callback
532525
dispatchCallback(options.progress_callback, {
533-
...progressInfo,
526+
status: 'progress',
527+
name: path_or_repo_id,
528+
file: filename,
534529
progress: 100,
535530
loaded: buffer.length,
536531
total: buffer.length,
537532
})
538533
} else {
539534
buffer = await readResponse(response, data => {
540535
dispatchCallback(options.progress_callback, {
541-
...progressInfo,
536+
status: 'progress',
537+
name: path_or_repo_id,
538+
file: filename,
542539
...data,
543540
})
544541
})
@@ -595,12 +592,11 @@ export async function getModelJSON(modelPath, fileName, fatal = true, options =
595592

596593
return JSON.parse(jsonData);
597594
}
598-
599595
/**
600596
* Read and track progress when reading a Response object
601597
*
602-
* @param {any} response The Response object to read
603-
* @param {function} progress_callback The function to call with progress updates
598+
* @param {Response|FileResponse} response The Response object to read
599+
* @param {(data: {progress: number, loaded: number, total: number}) => void} progress_callback The function to call with progress updates
604600
* @returns {Promise<Uint8Array>} A Promise that resolves with the Uint8Array buffer
605601
*/
606602
async function readResponse(response, progress_callback) {

0 commit comments

Comments
 (0)