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 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;
|
||||||
}
|
}
|
||||||
@@ -112,12 +110,12 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
|
|||||||
try {
|
try {
|
||||||
console.log('Attempting NanoGPT...');
|
console.log('Attempting NanoGPT...');
|
||||||
const aiResponse = await callNanoGPT(messages, model);
|
const aiResponse = await callNanoGPT(messages, model);
|
||||||
|
|
||||||
// Update history on success
|
// Update history on success
|
||||||
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) {
|
||||||
@@ -136,12 +134,12 @@ export async function getAIResponse(prompt, channelId, mentionedUsername) {
|
|||||||
try {
|
try {
|
||||||
console.log('Attempting fallback (z.ai)...');
|
console.log('Attempting fallback (z.ai)...');
|
||||||
const aiResponse = await callFallbackAPI(messages);
|
const aiResponse = await callFallbackAPI(messages);
|
||||||
|
|
||||||
// Update history on success
|
// Update history on success
|
||||||
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');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user