From 758e76d73fa4198fc9a24c8ca5c3b093d2a62b67 Mon Sep 17 00:00:00 2001 From: evanboyle Date: Sun, 29 Dec 2024 22:51:11 -0800 Subject: [PATCH] add back streaming children example --- playground/index.tsx | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/playground/index.tsx b/playground/index.tsx index 042de526..43e6383d 100644 --- a/playground/index.tsx +++ b/playground/index.tsx @@ -37,6 +37,38 @@ async function runHNAnalysisExample() { ); } +async function runStreamingWithChildrenExample() { + const prompt = + "Write a 250 word story about an AI that discovers the meaning of friendship through a series of small interactions with humans. Be concise but meaningful."; + + console.log("\nšŸš€ Starting streaming example with prompt:", prompt); + + console.log("\nšŸ“ Non-streaming version (waiting for full response):"); + await gsx.execute( + + {async (response: string) => { + console.log(response); + }} + , + ); + + console.log("\nšŸ“ Streaming version (processing tokens as they arrive):"); + await gsx.execute( + + {async (response: Streamable) => { + // Print tokens as they arrive + for await (const token of { + [Symbol.asyncIterator]: () => response.stream(), + }) { + process.stdout.write(token); + } + process.stdout.write("\n"); + console.log("āœ… Streaming complete"); + }} + , + ); +} + // Example 3: Streaming vs non-streaming chat completion async function runStreamingExample() { const prompt = @@ -89,7 +121,7 @@ async function runRAGExample() { async function main() { await runBlogWritingExample(); await runHNAnalysisExample(); - // TODO add back streaming with children example... + await runStreamingWithChildrenExample(); await runStreamingExample(); await runRAGExample(); }