39 lines
985 B
TypeScript
39 lines
985 B
TypeScript
import { NextResponse } from "next/server"
|
|
|
|
const API_KEY = 'app-lbe2lglt7taGtZk0dG7pAhbx'
|
|
const API_URL = 'http://df.clkeji.com/v1/chat-messages'
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json()
|
|
|
|
const response = await fetch(API_URL, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': `Bearer ${API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify(body),
|
|
})
|
|
|
|
if (body.response_mode === 'streaming') {
|
|
return new NextResponse(response.body, {
|
|
headers: {
|
|
'Content-Type': 'text/event-stream',
|
|
'Cache-Control': 'no-cache',
|
|
'Connection': 'keep-alive',
|
|
},
|
|
})
|
|
}
|
|
|
|
const data = await response.json()
|
|
return NextResponse.json(data)
|
|
} catch (error) {
|
|
console.error('Chat API error:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to connect to chat service' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|