Skip to content

Commit ec3049c

Browse files
committed
Add information about vendoring and patching TextDecoderStream polyfill
1 parent a722df3 commit ec3049c

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

README.md

+26-12
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ app.get('/webhooks/replicate', async (c) => {
110110
const prediction = await c.req.json();
111111
console.log(prediction);
112112
//=> {"id": "xyz", "status": "successful", ... }
113-
113+
114114
// Acknowledge the webhook.
115115
c.status(200);
116116
c.json({ok: true});
@@ -217,15 +217,15 @@ Run a model and await the result. Unlike [`replicate.prediction.create`](#replic
217217
const output = await replicate.run(identifier, options, progress);
218218
```
219219

220-
| name | type | description |
221-
| ------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
222-
| `identifier` | string | **Required**. The model version identifier in the format `{owner}/{name}:{version}`, for example `stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f` |
223-
| `options.input` | object | **Required**. An object with the model inputs. |
224-
| `options.wait` | object | Options for waiting for the prediction to finish |
225-
| `options.wait.interval` | number | Polling interval in milliseconds. Defaults to 500 |
226-
| `options.webhook` | string | An HTTPS URL for receiving a webhook when the prediction has new output |
227-
| `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` |
228-
| `options.signal` | object | An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the prediction |
220+
| name | type | description |
221+
| ------------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
222+
| `identifier` | string | **Required**. The model version identifier in the format `{owner}/{name}:{version}`, for example `stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f` |
223+
| `options.input` | object | **Required**. An object with the model inputs. |
224+
| `options.wait` | object | Options for waiting for the prediction to finish |
225+
| `options.wait.interval` | number | Polling interval in milliseconds. Defaults to 500 |
226+
| `options.webhook` | string | An HTTPS URL for receiving a webhook when the prediction has new output |
227+
| `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` |
228+
| `options.signal` | object | An [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) to cancel the prediction |
229229
| `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. |
230230

231231
Throws `Error` if the prediction failed.
@@ -246,7 +246,7 @@ Example that logs progress as the model is running:
246246
const model = "stability-ai/sdxl:8beff3369e81422112d93b89ca01426147de542cd4684c244b673b105188fe5f";
247247
const input = { prompt: "a 19th century portrait of a raccoon gentleman wearing a suit" };
248248
const onProgress = (prediction) => {
249-
const last_log_line = prediction.logs.split("\n").pop()
249+
const last_log_line = prediction.logs.split("\n").pop()
250250
console.log({id: prediction.id, log: last_log_line})
251251
}
252252
const output = await replicate.run(model, { input }, onProgress)
@@ -875,6 +875,20 @@ The `Replicate` constructor and all `replicate.*` methods are fully typed.
875875

876876
We have a few dependencies that have been bundled into the vendor directory rather than adding external npm dependencies.
877877

878-
These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information.
878+
These have been generated using bundlejs.com and copied into the appropriate directory along with the license and repository information.
879879

880880
* [eventsource-parser/stream](https://bundlejs.com/?bundle&q=eventsource-parser%40latest%2Fstream&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%2C%22platform%22%3A%22neutral%22%7D%7D)
881+
* [streams-text-encoding/text-decoder-stream](https://bundlejs.com/?q=%40stardazed%2Fstreams-text-encoding&treeshake=%5B%7B+TextDecoderStream+%7D%5D&config=%7B%22esbuild%22%3A%7B%22format%22%3A%22cjs%22%2C%22minify%22%3Afalse%7D%7D)
882+
883+
> [!NOTE]
884+
> The vendored implementation of `TextDecoderStream` requires
885+
> the following patch to be applied to the output of bundlejs.com:
886+
> ```difff
887+
> constructor(label, options) {
888+
> - this[decDecoder] = new TextDecoder(label, options);
889+
> - this[decTransform] = new TransformStream(new TextDecodeTransformer(this[decDecoder]));
890+
> }
891+
> + const decoder = new TextDecoder(label || "utf-8", options || {});
892+
> + this[decDecoder] = decoder;
893+
> + this[decTransform] = new TransformStream(new TextDecodeTransformer(decoder));
894+
> ```

vendor/streams-text-encoding/text-decoder-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Adapted from https://github.com/stardazed/sd-streams
1+
// Adapted from https://github.com/stardazed/sd-streams
22
//
33
// MIT License
44
//

0 commit comments

Comments
 (0)