Streaming

Now lets add streaming support...

import { ChatPrompt } from '@microsoft/spark.ai'; import { OpenAIChatModel } from '@microsoft/spark.openai'; const prompt = new ChatPrompt({ instructions: [ 'you are an assistant that helps find the perfect emoji to use for a given situation.', 'you will only respond with emojis.', ].join('\n'), model: new OpenAIChatModel({ model: 'gpt-4o', apiKey: process.OPENAI_API_KEY, stream: true, }), }); (async () => { await prompt.chat('having a great day!', (chunk) => { process.stdout.write(chunk); // 😄🌞🎉 }); process.stdout.write('\n'); })();