Skip to content

Commit c8a4cc6

Browse files
committed
fix: Streaming for NodeJS
1 parent db9db98 commit c8a4cc6

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

examples/studio/chat/stream-chat-completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function main() {
1717
}
1818

1919
process.stdout.write('\n');
20-
20+
2121
// Explicitly exit after stream completion
2222
process.exit(0);
2323
} catch (error) {

src/streaming/SSEDecoder.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class BaseSSEDecoder implements SSEDecoder {
2424
if (!response.body) {
2525
throw new Error('Response body is null');
2626
}
27-
27+
2828
yield* this._iterLines(this.getReader(response));
2929
}
3030

@@ -73,18 +73,17 @@ export class NodeSSEDecoder extends BaseSSEDecoder {
7373
async start(controller) {
7474
try {
7575
for await (const chunk of stream) {
76-
const uint8Array = typeof chunk === 'string'
77-
? new TextEncoder().encode(chunk)
78-
: chunk instanceof Uint8Array
79-
? chunk
80-
: new Uint8Array(chunk);
76+
const uint8Array =
77+
typeof chunk === 'string' ? new TextEncoder().encode(chunk)
78+
: chunk instanceof Uint8Array ? chunk
79+
: new Uint8Array(chunk);
8180
controller.enqueue(uint8Array);
8281
}
8382
controller.close();
8483
} catch (error) {
8584
controller.error(error);
8685
}
87-
}
86+
},
8887
});
8988
return webStream.getReader();
9089
}

0 commit comments

Comments
 (0)