Skip to content

Commit 7c3bd45

Browse files
committed
Remove wait parameter from predictions.create
1 parent 972623c commit 7c3bd45

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,17 @@ class Replicate {
8080
* @param {string} identifier - Required. The model version identifier in the format "{owner}/{name}:{version}"
8181
* @param {object} options
8282
* @param {object} options.input - Required. An object with the model inputs
83-
* @param {object} [options.wait] - Whether to wait for the prediction to finish. Defaults to false
83+
* @param {object} [options.wait] - Options for waiting for the prediction to finish
8484
* @param {number} [options.wait.interval] - Polling interval in milliseconds. Defaults to 250
85-
* @param {number} [options.wait.maxAttempts] - Maximum number of polling attempts. Defaults to no limit
85+
* @param {number} [options.wait.max_attempts] - Maximum number of polling attempts. Defaults to no limit
8686
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
8787
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
8888
* @throws {Error} If the prediction failed
8989
* @returns {Promise<object>} - Resolves with the output of running the model
9090
*/
9191
async run(identifier, options) {
92+
const { wait, ...data } = options;
93+
9294
// Define a pattern for owner and model names that allows
9395
// letters, digits, and certain special characters.
9496
// Example: "user123", "abc__123", "user.name"
@@ -108,12 +110,14 @@ class Replicate {
108110
}
109111

110112
const { version } = match.groups;
111-
const prediction = await this.predictions.create({
112-
wait: true,
113-
...options,
113+
114+
let prediction = await this.predictions.create({
115+
...data,
114116
version,
115117
});
116118

119+
prediction = await this.wait(prediction, wait || {});
120+
117121
if (prediction.status === 'failed') {
118122
throw new Error(`Prediction failed: ${prediction.error}`);
119123
}

lib/predictions.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
* @param {object} options
55
* @param {string} options.version - Required. The model version
66
* @param {object} options.input - Required. An object with the model inputs
7-
* @param {boolean|object} [options.wait] - Whether to wait for the prediction to finish. Defaults to false
8-
* @param {number} [options.wait.interval] - Polling interval in milliseconds. Defaults to 250
9-
* @param {number} [options.wait.maxAttempts] - Maximum number of polling attempts. Defaults to no limit
107
* @param {string} [options.webhook] - An HTTPS URL for receiving a webhook when the prediction has new output
118
* @param {string[]} [options.webhook_events_filter] - You can change which events trigger webhook requests by specifying webhook events (`start`|`output`|`logs`|`completed`)
129
* @param {boolean} [options.stream] - Whether to stream the prediction output. Defaults to false
@@ -26,19 +23,9 @@ async function createPrediction(options) {
2623

2724
const response = await this.request('/predictions', {
2825
method: 'POST',
29-
data,
26+
data: { ...data, stream },
3027
});
3128

32-
if (wait) {
33-
const { maxAttempts, interval } = wait;
34-
35-
// eslint-disable-next-line no-promise-executor-return
36-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
37-
await sleep(interval || 250);
38-
39-
return this.wait(await response, { maxAttempts, interval });
40-
}
41-
4229
return response.json();
4330
}
4431

0 commit comments

Comments
 (0)