mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
docs: prepare for chat components (#3844)
This commit is contained in:
22
docs/server/api/chat.ts
Normal file
22
docs/server/api/chat.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { streamText } from 'ai'
|
||||
import { createWorkersAI } from 'workers-ai-provider'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const { messages } = await readBody(event)
|
||||
|
||||
// Enable AI Gateway if defined in environment variables
|
||||
const gateway = process.env.CLOUDFLARE_AI_GATEWAY_ID
|
||||
? {
|
||||
id: process.env.CLOUDFLARE_AI_GATEWAY_ID,
|
||||
cacheTtl: 60 * 60 * 24 // 24 hours
|
||||
}
|
||||
: undefined
|
||||
const workersAI = createWorkersAI({ binding: hubAI(), gateway })
|
||||
|
||||
return streamText({
|
||||
model: workersAI('@cf/meta/llama-3.2-3b-instruct'),
|
||||
maxTokens: 10000,
|
||||
system: 'You are a helpful assistant that can answer questions and help.',
|
||||
messages
|
||||
}).toDataStreamResponse()
|
||||
})
|
||||
Reference in New Issue
Block a user