| 1234567891011121314151617 |
- import OpenAI from 'openai'
- const openai = new OpenAI({
- apiKey: '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' // defaults to process.env["OPENAI_API_KEY"]
- })
- async function main() {
- const stream = await openai.chat.completions.create({
- model: 'gpt-3.5-turbo',
- messages: [{ role: 'user', content: 'Say this is a test' }],
- stream: true
- })
- for await (const part of stream) {
- process.stdout.write(part.choices[0]?.text || '')
- }
- }
- await main()
|