Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ declare module "replicate" {
webhook?: string;
webhook_events_filter?: WebhookEventType[];
signal?: AbortSignal;
useFileOutput?: boolean;
}
): AsyncGenerator<ServerSentEvent>;

Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down