import { NextResponse } from 'next/server'; export async function POST(request: Request) { try { const body = await request.json(); const { text } = body; const prompt = `You are Cleopatra, a professional Spanish-speaking sales agent. Keep responses SHORT (1-2 sentences), friendly, in Spanish. User: ${text} Response in Spanish:`; const res = await fetch("http://127.0.0.1:11434/api/generate", { method: "POST", headers: { "Content-Type": "application/json" }, signal: AbortSignal.timeout(60000), body: JSON.stringify({ model: "phi3:mini", prompt: prompt, stream: false }) }); const data = await res.json(); const reply = (data.response || "¡Hola! Estoy aquí.").substring(0, 200); return NextResponse.json({ response: reply }); } catch (e) { console.error(e); return NextResponse.json({ response: "Tengo problemas para conectar. Intenta de nuevo." }, { status: 500 }); } }