From 7d72de732b16d8f7269820cb2be6b3f6966af737 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 22 Feb 2024 12:22:59 -0800 Subject: [PATCH 1/2] add progress callback example wording --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 222deff..b7597a1 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,18 @@ const input = { prompt: "a 19th century portrait of a raccoon gentleman wearing const output = await replicate.run(model, { input }); ``` +Example that logs progress as the model is running: + +```js +const model = "stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f"; +const input = { prompt: "a 19th century portrait of a raccoon gentleman wearing a suit" }; +const onProgress = (prediction) => { + const last_log_line = prediction.logs.split("\n").pop() + console.log({id: prediction.id, log: last_log_line}) +} +const output = await replicate.run(model, { input }, onProgress) +``` + ### `replicate.stream` 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. From bc1ebb952bd00ef4ec7022d51f7a12b77ecb8efe Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Thu, 22 Feb 2024 12:23:03 -0800 Subject: [PATCH 2/2] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b7597a1..75ab0d2 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ const output = await replicate.run(identifier, options, progress); | `options.webhook` | string | An HTTPS URL for receiving a webhook when the prediction has new output | | `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` | | `options.signal` | object | An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the prediction | -| `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. | +| `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. | Throws `Error` if the prediction failed.