fix: use x-api-key header for minimax
This commit is contained in:
@@ -116,29 +116,47 @@ function extractJson(text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function anthConfig() {
|
||||
const base =
|
||||
(process.env.ANTHROPIC_BASE_URL || '').trim() ||
|
||||
(process.env.ANTHROPIC_FALLBACK_BASE_URL || '').trim();
|
||||
const token =
|
||||
function anthConfigs() {
|
||||
const configs = [];
|
||||
const primaryBase = (process.env.ANTHROPIC_BASE_URL || '').trim();
|
||||
const primaryToken =
|
||||
(process.env.ANTHROPIC_AUTH_TOKEN || '').trim() ||
|
||||
(process.env.ANTHROPIC_FALLBACK_TOKEN || '').trim();
|
||||
if (!base || !token) {
|
||||
return null;
|
||||
(process.env.ANTHROPIC_API_KEY || '').trim();
|
||||
if (primaryBase && primaryToken) {
|
||||
configs.push({
|
||||
endpoint: `${primaryBase.replace(/\/$/, '')}/v1/messages`,
|
||||
token: primaryToken,
|
||||
model: process.env.ANTHROPIC_MODEL || 'claude-3-5-sonnet-20241022'
|
||||
});
|
||||
}
|
||||
return {
|
||||
endpoint: `${base.replace(/\/$/, '')}/v1/messages`,
|
||||
token
|
||||
};
|
||||
const fallbackBase = (process.env.ANTHROPIC_FALLBACK_BASE_URL || '').trim();
|
||||
const fallbackToken = (process.env.ANTHROPIC_FALLBACK_TOKEN || '').trim();
|
||||
if (fallbackBase && fallbackToken) {
|
||||
const sameAsPrimary =
|
||||
fallbackBase === primaryBase && fallbackToken === primaryToken;
|
||||
if (!sameAsPrimary) {
|
||||
configs.push({
|
||||
endpoint: `${fallbackBase.replace(/\/$/, '')}/v1/messages`,
|
||||
token: fallbackToken,
|
||||
model:
|
||||
process.env.ANTHROPIC_FALLBACK_MODEL ||
|
||||
process.env.ANTHROPIC_MODEL ||
|
||||
'claude-3-5-sonnet-20241022'
|
||||
});
|
||||
}
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
async function callAnthropic(systemText, userText, maxTokens = 800) {
|
||||
const cfg = anthConfig();
|
||||
if (!cfg) {
|
||||
const configs = anthConfigs();
|
||||
if (!configs.length) {
|
||||
return null;
|
||||
}
|
||||
let lastError = null;
|
||||
for (const cfg of configs) {
|
||||
const payload = {
|
||||
model: process.env.ANTHROPIC_MODEL || 'claude-3-5-sonnet-20241022',
|
||||
model: cfg.model || process.env.ANTHROPIC_MODEL || 'claude-3-5-sonnet-20241022',
|
||||
max_tokens: maxTokens,
|
||||
temperature: 0.3,
|
||||
system: systemText,
|
||||
@@ -166,10 +184,19 @@ async function callAnthropic(systemText, userText, maxTokens = 800) {
|
||||
const data = await res.json();
|
||||
return data?.content?.[0]?.text || '';
|
||||
} catch (err) {
|
||||
console.warn('[alsGenerator] Anthropic error:', err.message);
|
||||
return null;
|
||||
lastError = err;
|
||||
console.warn(
|
||||
`[alsGenerator] Anthropic error (${cfg.endpoint}):`,
|
||||
err.message
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (lastError) {
|
||||
console.warn('[alsGenerator] All Anthropic endpoints failed.');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function planWithAI(prompt, library, sources) {
|
||||
const cfg = anthConfig();
|
||||
|
||||
Reference in New Issue
Block a user