Skip to content

Commit 5f8cfde

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, and deprecates the `block` parameter.
1 parent 2b55fcb commit 5f8cfde

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/deployments.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ 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
13+
* @param {boolean} [options.block] - DEPRECATED: Whether to wait until the prediction is completed before returning. Defaults to false
1314
* @returns {Promise<object>} Resolves with the created prediction data
1415
*/
1516
async function createPrediction(deployment_owner, deployment_name, options) {
16-
const { input, block, ...data } = options;
17+
const { input, wait, block, ...data } = options;
1718

1819
if (data.webhook) {
1920
try {
@@ -25,7 +26,14 @@ async function createPrediction(deployment_owner, deployment_name, options) {
2526
}
2627

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

0 commit comments

Comments
 (0)