@@ -200,12 +200,10 @@ Note: This is only supported for text-generation models.
200200
201201``` js
202202const 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
14241420const 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