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
Document the FileOutput and wait parameters (#326)
This commit takes a first pass at documenting the `FileOutput` and `wait` parameters introduced in 1.0.0 as well as calling out various potential gotchas with the API around URLs and data-uris based on feedback from the issues.
> A model that outputs file data returns a `FileOutput` object by default. This is an implementation
69
+
> of `ReadableStream` that returns the file contents. It has a `.blob()` method for accessing a
70
+
> `Blob` representation and a `.url()` method that will return the underlying data-source.
71
+
>
72
+
> **This data source can be either a remote URL or a data-uri with base64 encoded data. Check
73
+
> out the documentation on [creating a prediction](https://replicate.com/docs/topics/predictions/create-a-prediction)
74
+
> for more information.**
75
+
67
76
You can also run a model in the background:
68
77
69
78
```js
@@ -277,6 +286,7 @@ const replicate = new Replicate(options);
277
286
|`options.baseUrl`| string | Defaults to https://api.replicate.com/v1|
278
287
|`options.fetch`| function | Fetch function to use. Defaults to `globalThis.fetch`|
279
288
|`options.fileEncodingStrategy`| string | Determines the file encoding strategy to use. Possible values: `"default"`, `"upload"`, or `"data-uri"`. Defaults to `"default"`|
289
+
|`options.useFileOutput`| boolean | Determines if the `replicate.run()` method should convert file output into `FileOutput` objects |
280
290
281
291
282
292
The client makes requests to Replicate's API using
|`identifier`| string |**Required**. The model version identifier in the format `{owner}/{name}:{version}`, for example `stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f`|
335
345
|`options.input`| object |**Required**. An object with the model inputs. |
336
-
|`options.wait`| object | Options for waiting for the prediction to finish |
337
-
|`options.wait.interval`| number | Polling interval in milliseconds. Defaults to 500 |
346
+
|`options.wait`| object | Options for waiting for the prediction to finish |
347
+
|`options.wait.type`|`"poll" \| "block"`|`"block"` holds the request open, `"poll"` makes repeated requests to fetch the prediction. Defaults to `"block"`|
348
+
|`options.wait.interval`| number | Polling interval in milliseconds. Defaults to 500 |
349
+
|`options.wait.timeout`| number | In `"block"` mode determines how long the request will be held open until falling back to polling. Defaults to 60 |
338
350
|`options.webhook`| string | An HTTPS URL for receiving a webhook when the prediction has new output |
339
351
|`options.webhook_events_filter`| string[]| An array of events which should trigger [webhooks](https://replicate.com/docs/webhooks). Allowable values are `start`, `output`, `logs`, and `completed`|
340
352
|`options.signal`| object | An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the prediction |
341
353
|`progress`| function | Callback function that receives the prediction object as it's updated. The function is called when the prediction is created, each time it's updated while polling for completion, and when it's completed. |
342
354
343
355
Throws `Error` if the prediction failed.
344
356
345
-
Returns `Promise<object>` which resolves with the output of running the model.
357
+
Returns `Promise<unknown>` which resolves with the output of running the model.
358
+
359
+
> [!NOTE]
360
+
> Currently the TypeScript return type of `replicate.run()` is `Promise<object>` this is
361
+
> misleading as a model can return array types as well as primative types like strings,
Run a model and stream its output. Unlike [`replicate.prediction.create`](#replicatepredictionscreate), this method returns only the prediction output rather than the entire prediction object.
@@ -1192,6 +1229,41 @@ The `replicate.request()` method is used by the other methods
1192
1229
to interact with the Replicate API.
1193
1230
You can call this method directly to make other requests to the API.
1194
1231
1232
+
### `FileOutput`
1233
+
1234
+
`FileOutput` is a `ReadableStream` instance that represents a model file output. It can be used to stream file data to disk or as a `Response` body to an HTTP request.
0 commit comments