Skip to content

Commit a0b8f96

Browse files
authored
Add progress callback example to replicate.run docs (#208)
* add progress callback example wording * typo
1 parent 497b434 commit a0b8f96

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ const output = await replicate.run(identifier, options, progress);
167167
| `options.webhook` | string | An HTTPS URL for receiving a webhook when the prediction has new output |
168168
| `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` |
169169
| `options.signal` | object | An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the prediction |
170-
| `progress` | function | Callback function that receives the prediction object as it's updated. The function is called when the prediction is created, each time its updated while polling for completion, and when it's completed. |
170+
| `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. |
171171

172172
Throws `Error` if the prediction failed.
173173

@@ -181,6 +181,18 @@ const input = { prompt: "a 19th century portrait of a raccoon gentleman wearing
181181
const output = await replicate.run(model, { input });
182182
```
183183

184+
Example that logs progress as the model is running:
185+
186+
```js
187+
const model = "stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f";
188+
const input = { prompt: "a 19th century portrait of a raccoon gentleman wearing a suit" };
189+
const onProgress = (prediction) => {
190+
const last_log_line = prediction.logs.split("\n").pop()
191+
console.log({id: prediction.id, log: last_log_line})
192+
}
193+
const output = await replicate.run(model, { input }, onProgress)
194+
```
195+
184196
### `replicate.stream`
185197

186198
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.

0 commit comments

Comments
 (0)