-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
24 lines (21 loc) · 814 Bytes
/
route.ts
File metadata and controls
24 lines (21 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { runBattle } from '@/lib/api-service'
import { BattleSetup } from '@/types'
export async function POST(req: Request) {
const battleSetup = await req.json()
const { userPrompt, selectedModels } = battleSetup as BattleSetup
// Validate required fields
if (!userPrompt) {
return new Response('userPrompt is required', { status: 400 })
}
if (!selectedModels?.length) {
return new Response('selectedModels is required', { status: 400 })
}
try {
const battleResponse = await runBattle(battleSetup, () => {})
return Response.json(battleResponse, { status: 200 })
} catch (error) {
console.error('Error running battle:', error)
const msg = error instanceof Error ? error.message : 'Internal server error'
return Response.json({ error: msg }, { status: 500 })
}
}