/ examples / js / ai-sdk / stream-text.ts
stream-text.ts
 1  /**
 2   * Stream Text Example
 3   * 
 4   * Demonstrates streaming text generation using AI SDK v6 via praisonai-ts.
 5   * 
 6   * Run: npx ts-node stream-text.ts
 7   * Required: OPENAI_API_KEY
 8   */
 9  
10  import { Agent } from '../../../src/praisonai-ts/src';
11  
12  async function main() {
13    const agent = new Agent({
14      instructions: 'You are a helpful assistant that provides detailed answers.',
15      llm: 'openai/gpt-4o-mini',
16      stream: true,
17    });
18  
19    console.log('=== Stream Text Example ===\n');
20    console.log('Streaming response:\n');
21  
22    // Stream the response
23    const response = await agent.chat('Explain quantum computing in 3 paragraphs.');
24    console.log('\n\nFinal response:', response);
25  }
26  
27  main().catch(console.error);