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
Add wait parameter to prediction creation methods (#308)
* Add block parameter to prediction creation methods
* Add support for block: or wait: true to run
* Remove unused stream parameter
* Apply suggestions from code review
Co-authored-by: Aron Carroll <[email protected]>
* Replace X-Sync header with Prefer: wait
* Rename block to wait
Update type definitions to capture expectations of wait parameter in run
* Normalize wait value to nonzero integer
---------
Co-authored-by: Aron Carroll <[email protected]>
Copy file name to clipboardExpand all lines: index.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,7 @@ class Replicate {
133
133
* @param {string} ref - Required. The model version identifier in the format "owner/name" or "owner/name:version"
134
134
* @param {object} options
135
135
* @param {object} options.input - Required. An object with the model inputs
136
-
* @param {object} [options.wait] - Options for waiting for the prediction to finish
136
+
* @param {object} [options.wait] - Options for waiting for the prediction to finish. If `wait` is explicitly true, the function will block and wait for the prediction to finish.
137
137
* @param {number} [options.wait.interval] - Polling interval in milliseconds. Defaults to 500
138
138
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
139
139
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
@@ -153,11 +153,13 @@ class Replicate {
153
153
prediction=awaitthis.predictions.create({
154
154
...data,
155
155
version: identifier.version,
156
+
wait: wait,
156
157
});
157
158
}elseif(identifier.owner&&identifier.name){
158
159
prediction=awaitthis.predictions.create({
159
160
...data,
160
161
model: `${identifier.owner}/${identifier.name}`,
162
+
wait: wait,
161
163
});
162
164
}else{
163
165
thrownewError("Invalid model version identifier");
* @param {string} deployment_name - Required. The name of the deployment
8
8
* @param {object} options
9
9
* @param {object} options.input - Required. An object with the model inputs
10
-
* @param {boolean} [options.stream] - Whether to stream the prediction output. Defaults to false
11
10
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
12
11
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
12
+
* @param {boolean} [options.block] - Whether to wait until the prediction is completed before returning. Defaults to false
13
13
* @returns {Promise<object>} Resolves with the created prediction data
* @param {object} options.input - Required. An object with the model inputs
10
10
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
11
11
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
12
-
* @param {boolean} [options.stream] - Whether to stream the prediction output. Defaults to false. Streaming is now enabled by default for all predictions. For more information, see https://replicate.com/changelog/2024-07-15-streams-always-available-stream-parameter-deprecated
12
+
* @param {boolean|integer} [options.wait] - Whether to wait until the prediction is completed before returning. If an integer is provided, it will wait for that many seconds. Defaults to false
13
13
* @returns {Promise<object>} Resolves with the created prediction
0 commit comments