basic-chat.ts
1 /** 2 * AI SDK Basic Chat Example 3 * 4 * Demonstrates simple text generation using the AI SDK backend. 5 * 6 * Usage: 7 * npx ts-node basic-chat.ts 8 * 9 * Environment: 10 * OPENAI_API_KEY - Your OpenAI API key 11 */ 12 13 import { createAISDKBackend } from 'praisonai'; 14 15 async function main() { 16 // Create backend with model string 17 const backend = createAISDKBackend('openai/gpt-4o-mini'); 18 19 console.log('Sending message to OpenAI...\n'); 20 21 // Generate text 22 const result = await backend.generateText({ 23 messages: [ 24 { role: 'system', content: 'You are a helpful assistant.' }, 25 { role: 'user', content: 'What are the three primary colors?' } 26 ], 27 maxTokens: 200, 28 temperature: 0.7, 29 }); 30 31 console.log('Response:', result.text); 32 console.log('\nFinish reason:', result.finishReason); 33 34 if (result.usage) { 35 console.log('Token usage:', result.usage); 36 } 37 } 38 39 main().catch(console.error);