Skip to content

Commit fc9032f

Browse files
committed
Update deployments.createPrediction to use wait
A first draft of this interface used `block`, but we ended up going with `wait` (as either a boolean or a number) for the predictions.createPrediction method. This commit brings the two implementations inline, removing the undocumented and unintended `block` parameter.
1 parent 2b55fcb commit fc9032f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/deployments.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const { transformFileInputs } = require("./util");
99
* @param {object} options.input - Required. An object with the model inputs
1010
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
1111
* @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
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
1313
* @returns {Promise<object>} Resolves with the created prediction data
1414
*/
1515
async function createPrediction(deployment_owner, deployment_name, options) {
16-
const { input, block, ...data } = options;
16+
const { input, wait, ...data } = options;
1717

1818
if (data.webhook) {
1919
try {
@@ -25,8 +25,13 @@ async function createPrediction(deployment_owner, deployment_name, options) {
2525
}
2626

2727
const headers = {};
28-
if (block) {
29-
headers["Prefer"] = "wait";
28+
if (wait) {
29+
if (typeof wait === "number") {
30+
const n = Math.max(1, Math.ceil(Number(wait)) || 1);
31+
headers["Prefer"] = `wait=${n}`;
32+
} else {
33+
headers["Prefer"] = "wait";
34+
}
3035
}
3136

3237
const response = await this.request(

0 commit comments

Comments
 (0)