test111.mjs 501 B

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