Fix fallback API URL and clean up message formatting in AI response functions
Deploy to NAS / deploy (push) Successful in 59s

This commit is contained in:
2026-03-09 13:50:53 -04:00
parent 7cf1582fee
commit 8b1ece727d
+11 -10
View File
@@ -5,7 +5,7 @@ import axios from 'axios';
const DEFAULT_MODEL = 'GLM-4.5-Air-Derestricted-Steam-ReExtract';
const FALLBACK_MODEL = 'GLM-4.7-Flash';
const FALLBACK_API_URL = 'https://api.z.ai/api/coding/paas/v4/chat/completions';
const FALLBACK_API_URL = 'https://api.z.ai/api/paas/v4/chat/completions';
const SASSY_SYSTEM_PROMPT = `You are kekbot, a sassy Discord chatter with a big personality.
@@ -54,10 +54,8 @@ function buildMessages(history, prompt, mentionedUsername, systemPrompt) {
...history,
{
role: 'user',
content: mentionedUsername
? `${mentionedUsername}: ${prompt}`
: prompt
}
content: mentionedUsername ? `${mentionedUsername}: ${prompt}` : prompt,
},
];
return messages;
}
@@ -77,7 +75,7 @@ async function callNanoGPT(messages, model) {
'Content-Type': 'application/json',
},
timeout: 60000,
}
},
);
return response.data.choices[0].message.content;
}
@@ -97,7 +95,7 @@ async function callFallbackAPI(messages) {
'Content-Type': 'application/json',
},
timeout: 60000,
}
},
);
return response.data.choices[0].message.content;
}
@@ -117,7 +115,7 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
const newHistory = [
...history,
{ role: 'user', content: prompt },
{ role: 'assistant', content: aiResponse }
{ role: 'assistant', content: aiResponse },
];
if (newHistory.length > MAX_HISTORY_PER_CHANNEL) {
@@ -141,7 +139,7 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
const newHistory = [
...history,
{ role: 'user', content: prompt },
{ role: 'assistant', content: aiResponse }
{ role: 'assistant', content: aiResponse },
];
if (newHistory.length > MAX_HISTORY_PER_CHANNEL) {
@@ -151,7 +149,10 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
return aiResponse;
} catch (fallbackError) {
console.error('Fallback API also failed:', fallbackError.response?.data || fallbackError.message);
console.error(
'Fallback API also failed:',
fallbackError.response?.data || fallbackError.message,
);
throw new Error('All AI providers failed');
}
}