Skip to content

Commit

Permalink
add back streaming children example
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBoyle committed Dec 30, 2024
1 parent 1fa147a commit 758e76d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(
<ChatCompletion prompt={prompt}>
{async (response: string) => {
console.log(response);
}}
</ChatCompletion>,
);

console.log("\n📝 Streaming version (processing tokens as they arrive):");
await gsx.execute(
<ChatCompletion stream={true} prompt={prompt}>
{async (response: Streamable<string>) => {
// 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");
}}
</ChatCompletion>,
);
}

// Example 3: Streaming vs non-streaming chat completion
async function runStreamingExample() {
const prompt =
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 758e76d

Please sign in to comment.