Chat & Stream

Chat completions and streaming.

1 min readEdit this page

Chat

const res = await ai.complete({
  messages: [{ role: 'user', content: 'Hello!' }],
  system: 'You are helpful.',
  temperature: 0.7
})

Stream

for await (const chunk of ai.stream({ messages })) {
  if (chunk.delta) process.stdout.write(chunk.delta)
  if (chunk.done) console.log(chunk.response)
}

HTTP endpoints

import { aiChat, aiChatStream } from '@restjs/ai'
 
app.post('/chat',        aiChat({ provider: ai }))
app.post('/chat/stream', aiChatStream({ provider: ai }))