From 309738c3af05a440864bc6eca125f83a4d78932c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sita=20B=C3=A9r=C3=A9t=C3=A9?= Date: Sat, 29 Mar 2025 08:02:10 +0800 Subject: [PATCH 1/2] Fix url key of createFileOutput options for streaming --- lib/stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stream.js b/lib/stream.js index 2c899bd..7fcee11 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -93,7 +93,7 @@ function createReadableStream({ url, fetch, options = {} }) { typeof data === "string" && (data.startsWith("https:") || data.startsWith("data:")) ) { - data = createFileOutput({ data, fetch }); + data = createFileOutput({ url: data, fetch }); } controller.enqueue(new ServerSentEvent(event.event, data, event.id)); From c2e5811a6577a9ed1c674be836f482ade888ecef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sita=20B=C3=A9r=C3=A9t=C3=A9?= Date: Sat, 29 Mar 2025 08:22:12 +0800 Subject: [PATCH 2/2] Enable user to controle the use of FileOutput for streaming --- index.d.ts | 1 + index.js | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index 2b183d0..678d7a0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -173,6 +173,7 @@ declare module "replicate" { webhook?: string; webhook_events_filter?: WebhookEventType[]; signal?: AbortSignal; + useFileOutput?: boolean; } ): AsyncGenerator; diff --git a/index.js b/index.js index b1248e7..5dbfc12 100644 --- a/index.js +++ b/index.js @@ -315,7 +315,7 @@ class Replicate { * @yields {ServerSentEvent} Each streamed event from the prediction */ async *stream(ref, options) { - const { wait, signal, ...data } = options; + const { wait, signal, useFileOutput = this.useFileOutput, ...data } = options; const identifier = ModelVersionIdentifier.parse(ref); @@ -338,7 +338,10 @@ class Replicate { const stream = createReadableStream({ url: prediction.urls.stream, fetch: this.fetch, - ...(signal ? { options: { signal } } : {}), + options: { + useFileOutput, + ...(signal ? { signal } : {}), + }, }); yield* streamAsyncIterator(stream);