45af56d9cf
Also added: - Memory API endpoints - Briefs API endpoints - AnveVoice stats API - Claude spawn API - TTS proxy - Cleopatra voice widget - api-auth middleware
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
const MINIMAX_API_KEY = process.env.MINIMAX_API_KEY || "sk-cp-aRrwyWpeY7iheh18JiqLNHkaz0Kude0MRYFt2w5fDzk-5026VI-HtO06_us_DQjJ8yHt4Qevgz-UE3F566cnjYDZPMSUGLLFgjUpwOiV0Ir0hTbeUclMeIQ";
|
|
const MINIMAX_URL = "https://api.minimax.io/v1/text/chatcompletion_v2";
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
const { text } = body;
|
|
|
|
// Cleopatra personality - short, friendly, Spanish
|
|
const systemPrompt = `Eres Cleopatra, una agente de ventas profesional hispanohablante.
|
|
Respuestas CORTAS (1-2 oraciones), amigables, en español.
|
|
Siempre suena interesada y servicial.
|
|
Si no entiendes algo, pide que repitan por favor.`;
|
|
|
|
const messages = [
|
|
{ role: "system", content: systemPrompt },
|
|
{ role: "user", content: text }
|
|
];
|
|
|
|
const res = await fetch(MINIMAX_URL, {
|
|
method: "POST",
|
|
headers: {
|
|
"Authorization": `Bearer ${MINIMAX_API_KEY}`,
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify({
|
|
model: "MiniMax-M2.7",
|
|
messages,
|
|
temperature: 0.8,
|
|
max_tokens: 150
|
|
})
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error("MiniMax API error");
|
|
}
|
|
|
|
const data = await res.json();
|
|
const reply = data.choices?.[0]?.message?.content?.trim() ||
|
|
"¡Estoy aquí para ayudarte! ¿Qué necesitas?";
|
|
|
|
return NextResponse.json({ response: reply.substring(0, 300) });
|
|
|
|
} catch (e) {
|
|
console.error("Chat error:", e);
|
|
return NextResponse.json({
|
|
response: "Tengo problemas para conectar. ¿Puedes intentar de nuevo?"
|
|
}, { status: 200 });
|
|
}
|
|
}
|