You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.js
+26-9Lines changed: 26 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -86,10 +86,11 @@ class Replicate {
86
86
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
87
87
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
88
88
* @param {AbortSignal} [options.signal] - AbortSignal to cancel the prediction
89
+
* @param {Function} [progress] - Callback function that receives the prediction object as it's updated. The function is called when the prediction is created, each time its updated while polling for completion, and when it's completed.
89
90
* @throws {Error} If the prediction failed
90
91
* @returns {Promise<object>} - Resolves with the output of running the model
91
92
*/
92
-
asyncrun(identifier,options){
93
+
asyncrun(identifier,options,progress){
93
94
const{ wait, ...data}=options;
94
95
95
96
// Define a pattern for owner and model names that allows
@@ -117,17 +118,32 @@ class Replicate {
117
118
version,
118
119
});
119
120
121
+
// Call progress callback with the initial prediction object
122
+
if(progress){
123
+
progress(prediction);
124
+
}
125
+
120
126
const{ signal }=options;
121
127
122
-
prediction=awaitthis.wait(prediction,wait||{},async({ id })=>{
0 commit comments