Spaces:
Paused
Paused
dr-data
Fix preview component: eliminate blinking, ensure HTML updates, add smooth transitions
dcd5e1d
| import { NextRequest, NextResponse } from "next/server"; | |
| import { MODELS } from "@/lib/providers"; | |
| export async function POST(request: NextRequest) { | |
| const body = await request.json(); | |
| const { model, provider, openrouterApiKey } = body; | |
| // Enhanced OpenRouter detection logic (same as main API) | |
| const isExplicitOpenRouter = provider === "openrouter" || !!openrouterApiKey; | |
| const modelExistsInHF = MODELS.find((m) => m.value === model || m.label === model); | |
| const isOpenRouterRequest = isExplicitOpenRouter || (!modelExistsInHF && model); | |
| const selectedModel = !isOpenRouterRequest | |
| ? MODELS.find((m) => m.value === model || m.label === model) | |
| : null; | |
| return NextResponse.json({ | |
| input: { model, provider, hasApiKey: !!openrouterApiKey }, | |
| detection: { | |
| isExplicitOpenRouter, | |
| modelExistsInHF: !!modelExistsInHF, | |
| isOpenRouterRequest, | |
| selectedModel: selectedModel?.value || null, | |
| modelToUse: isOpenRouterRequest ? model : selectedModel?.value | |
| } | |
| }); | |
| } | |