diff --git a/src/app/api/ai/route.ts b/src/app/api/ai/route.ts index 9974563..08b270f 100644 --- a/src/app/api/ai/route.ts +++ b/src/app/api/ai/route.ts @@ -40,29 +40,42 @@ export async function POST(request: Request) { const allMessages = [systemMessage, ...messages]; - // Call LiteLLM - const response = await fetch(`${LITELLM_BASE_URL}/chat/completions`, { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${LITELLM_API_KEY}`, - }, - body: JSON.stringify({ - model: "minimax/Abab7.5-chat", - messages: allMessages, - max_tokens: 500, - }), - }); + // Try different MiniMax model formats + const models = [ + "minimax/Abab7.5-chat", + "minimax/Abab7-Chat", + "azure/gpt-4o-mini", + "gpt-4o-mini", + ]; - if (!response.ok) { - const error = await response.text(); - return NextResponse.json({ error: error }, { status: response.status }); + let lastError = ""; + for (const model of models) { + try { + const response = await fetch(`${LITELLM_BASE_URL}/chat/completions`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${LITELLM_API_KEY}`, + }, + body: JSON.stringify({ + model, + messages: allMessages, + max_tokens: 500, + }), + }); + + if (response.ok) { + const data = await response.json(); + const reply = data.choices?.[0]?.message?.content || "Sorry, I couldn't get a response."; + return NextResponse.json({ reply }); + } + lastError = await response.text(); + } catch (e) { + lastError = String(e); + } } - const data = await response.json(); - const reply = data.choices?.[0]?.message?.content || "Sorry, I couldn't get a response."; - - return NextResponse.json({ reply }); + return NextResponse.json({ error: "No models available: " + lastError }, { status: 500 }); } catch (error) { console.error(error); return NextResponse.json({ error: String(error) }, { status: 500 });