Skip to content

Fix url key of createFileOutput options for streaming #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
@@ -173,6 +173,7 @@ declare module "replicate" {
webhook?: string;
webhook_events_filter?: WebhookEventType[];
signal?: AbortSignal;
useFileOutput?: boolean;
}
): AsyncGenerator<ServerSentEvent>;

7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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);
2 changes: 1 addition & 1 deletion lib/stream.js
Original file line number Diff line number Diff line change
@@ -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));