Skip to content

Commit 18674d2

Browse files
committed
add progress callback example
1 parent 497b434 commit 18674d2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 prediction 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)