Fix fallback API URL and clean up message formatting in AI response functions
Deploy to NAS / deploy (push) Successful in 59s
Deploy to NAS / deploy (push) Successful in 59s
This commit is contained in:
+13
-12
@@ -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;
|
||||
}
|
||||
@@ -112,12 +110,12 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
|
||||
try {
|
||||
console.log('Attempting NanoGPT...');
|
||||
const aiResponse = await callNanoGPT(messages, model);
|
||||
|
||||
|
||||
// Update history on success
|
||||
const newHistory = [
|
||||
...history,
|
||||
{ role: 'user', content: prompt },
|
||||
{ role: 'assistant', content: aiResponse }
|
||||
{ role: 'assistant', content: aiResponse },
|
||||
];
|
||||
|
||||
if (newHistory.length > MAX_HISTORY_PER_CHANNEL) {
|
||||
@@ -136,12 +134,12 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
|
||||
try {
|
||||
console.log('Attempting fallback (z.ai)...');
|
||||
const aiResponse = await callFallbackAPI(messages);
|
||||
|
||||
|
||||
// Update history on success
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user