Try multiple model names for AI API
This commit is contained in:
parent
4e9935cb74
commit
89ca48b420
1 changed files with 33 additions and 20 deletions
|
|
@ -40,7 +40,17 @@ export async function POST(request: Request) {
|
|||
|
||||
const allMessages = [systemMessage, ...messages];
|
||||
|
||||
// Call LiteLLM
|
||||
// Try different MiniMax model formats
|
||||
const models = [
|
||||
"minimax/Abab7.5-chat",
|
||||
"minimax/Abab7-Chat",
|
||||
"azure/gpt-4o-mini",
|
||||
"gpt-4o-mini",
|
||||
];
|
||||
|
||||
let lastError = "";
|
||||
for (const model of models) {
|
||||
try {
|
||||
const response = await fetch(`${LITELLM_BASE_URL}/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -48,21 +58,24 @@ export async function POST(request: Request) {
|
|||
Authorization: `Bearer ${LITELLM_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "minimax/Abab7.5-chat",
|
||||
model,
|
||||
messages: allMessages,
|
||||
max_tokens: 500,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.text();
|
||||
return NextResponse.json({ error: error }, { status: response.status });
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "No models available: " + lastError }, { status: 500 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ error: String(error) }, { status: 500 });
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue