Skip to content

Commit d856b81

Browse files
committed
Merge branch 'main' of https://github.com/Bytez-com/docs into main
2 parents 94b4d83 + 4246ba3 commit d856b81

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

javascript/README.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,10 @@ Note: This is only supported for text-generation models.
200200

201201
```js
202202
const stream = await model.run("Jack and Jill", { stream: true });
203-
const reader = stream.getReader();
203+
const textStream = stream.pipeThrough(new TextDecoderStream());
204204

205-
while (true) {
206-
const { done, value } = await reader.read();
207-
if (done) break;
208-
console.log(new TextDecoder().decode(value));
205+
for await (const chunk of textStream) {
206+
console.log(chunk);
209207
}
210208
```
211209

@@ -1182,12 +1180,10 @@ const stream = await model.run(
11821180
{ stream: true, ...modelParams }
11831181
);
11841182

1185-
const reader = stream.getReader();
1183+
const textStream = stream.pipeThrough(new TextDecoderStream());
11861184

1187-
while (true) {
1188-
const { done, value } = await reader.read();
1189-
if (done) break;
1190-
console.log(new TextDecoder().decode(value));
1185+
for await (const chunk of textStream) {
1186+
console.log(chunk);
11911187
}
11921188
```
11931189
@@ -1423,12 +1419,10 @@ const prompt = promptTemplate.replace("{query}", inputText);
14231419

14241420
const stream = await model.run(prompt, { stream: true, params: modelParams });
14251421

1426-
const reader = stream.getReader();
1422+
const textStream = stream.pipeThrough(new TextDecoderStream());
14271423

1428-
while (true) {
1429-
const { done, value } = await reader.read();
1430-
if (done) break;
1431-
console.log(new TextDecoder().decode(value));
1424+
for await (const chunk of textStream) {
1425+
console.log(chunk);
14321426
}
14331427
```
14341428

0 commit comments

Comments
 (0)