Skip to content

Commit 469f8da

Browse files
authored
Prevent signal parameter from being passed alongside input when calling replicate.stream (#254)
* Prevent signal parameter from being passed alongside input when calling replicate.stream * Add test coverage for passing signal to replicate.stream
1 parent bb5ddaf commit 469f8da

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class Replicate {
274274
* @yields {ServerSentEvent} Each streamed event from the prediction
275275
*/
276276
async *stream(ref, options) {
277-
const { wait, ...data } = options;
277+
const { wait, signal, ...data } = options;
278278

279279
const identifier = ModelVersionIdentifier.parse(ref);
280280

@@ -296,11 +296,10 @@ class Replicate {
296296
}
297297

298298
if (prediction.urls && prediction.urls.stream) {
299-
const { signal } = options;
300299
const stream = createReadableStream({
301300
url: prediction.urls.stream,
302301
fetch: this.fetch,
303-
options: { signal },
302+
...(signal ? { options: { signal } } : {}),
304303
});
305304

306305
yield* streamAsyncIterator(stream);

integration/cloudflare-worker/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ export default {
55
const replicate = new Replicate({ auth: env.REPLICATE_API_TOKEN });
66

77
try {
8+
const controller = new AbortController();
89
const output = replicate.stream(
910
"replicate/canary:30e22229542eb3f79d4f945dacb58d32001b02cc313ae6f54eef27904edf3272",
1011
{
1112
input: {
1213
text: "Colin CloudFlare",
1314
},
15+
signal: controller.signal,
1416
}
1517
);
1618
const stream = new ReadableStream({

0 commit comments

Comments
 (0)