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 DEFAULT_MODEL = 'GLM-4.5-Air-Derestricted-Steam-ReExtract';
const FALLBACK_MODEL = 'GLM-4.7-Flash'; 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. 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, ...history,
{ {
role: 'user', role: 'user',
content: mentionedUsername content: mentionedUsername ? `${mentionedUsername}: ${prompt}` : prompt,
? `${mentionedUsername}: ${prompt}` },
: prompt
}
]; ];
return messages; return messages;
} }
@@ -77,7 +75,7 @@ async function callNanoGPT(messages, model) {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
timeout: 60000, timeout: 60000,
} },
); );
return response.data.choices[0].message.content; return response.data.choices[0].message.content;
} }
@@ -97,7 +95,7 @@ async function callFallbackAPI(messages) {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
timeout: 60000, timeout: 60000,
} },
); );
return response.data.choices[0].message.content; return response.data.choices[0].message.content;
} }
@@ -117,7 +115,7 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
const newHistory = [ const newHistory = [
...history, ...history,
{ role: 'user', content: prompt }, { role: 'user', content: prompt },
{ role: 'assistant', content: aiResponse } { role: 'assistant', content: aiResponse },
]; ];
if (newHistory.length > MAX_HISTORY_PER_CHANNEL) { if (newHistory.length > MAX_HISTORY_PER_CHANNEL) {
@@ -141,7 +139,7 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
const newHistory = [ const newHistory = [
...history, ...history,
{ role: 'user', content: prompt }, { role: 'user', content: prompt },
{ role: 'assistant', content: aiResponse } { role: 'assistant', content: aiResponse },
]; ];
if (newHistory.length > MAX_HISTORY_PER_CHANNEL) { if (newHistory.length > MAX_HISTORY_PER_CHANNEL) {
@@ -151,7 +149,10 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
return aiResponse; return aiResponse;
} catch (fallbackError) { } 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'); throw new Error('All AI providers failed');
} }
} }