Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/deployments.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const { transformFileInputs } = require("./util");
* @param {object} options.input - Required. An object with the model inputs
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
* @param {boolean} [options.block] - Whether to wait until the prediction is completed before returning. Defaults to false
* @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
* @returns {Promise<object>} Resolves with the created prediction data
*/
async function createPrediction(deployment_owner, deployment_name, options) {
const { input, block, ...data } = options;
const { input, wait, ...data } = options;

if (data.webhook) {
try {
Expand All @@ -25,8 +25,13 @@ async function createPrediction(deployment_owner, deployment_name, options) {
}

const headers = {};
if (block) {
headers["Prefer"] = "wait";
if (wait) {
if (typeof wait === "number") {
const n = Math.max(1, Math.ceil(Number(wait)) || 1);
headers["Prefer"] = `wait=${n}`;
} else {
headers["Prefer"] = "wait";
}
}

const response = await this.request(
Expand Down