fallback changes from PR #35
This commit is contained in:
@@ -18,6 +18,7 @@ import { logger } from '../utils/logger.js';
|
||||
import { parseResetTime } from './rate-limit-parser.js';
|
||||
import { buildCloudCodeRequest, buildHeaders } from './request-builder.js';
|
||||
import { parseThinkingSSEResponse } from './sse-parser.js';
|
||||
import { getFallbackModel } from '../fallback-config.js';
|
||||
|
||||
/**
|
||||
* Send a non-streaming request to Cloud Code with multi-account support
|
||||
@@ -32,7 +33,7 @@ import { parseThinkingSSEResponse } from './sse-parser.js';
|
||||
* @returns {Promise<Object>} Anthropic-format response object
|
||||
* @throws {Error} If max retries exceeded or no accounts available
|
||||
*/
|
||||
export async function sendMessage(anthropicRequest, accountManager) {
|
||||
export async function sendMessage(anthropicRequest, accountManager, fallbackEnabled = false) {
|
||||
const model = anthropicRequest.model;
|
||||
const isThinking = isThinkingModel(model);
|
||||
|
||||
@@ -76,6 +77,16 @@ export async function sendMessage(anthropicRequest, accountManager) {
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
// Check if fallback is enabled and available
|
||||
if (fallbackEnabled) {
|
||||
const fallbackModel = getFallbackModel(model);
|
||||
if (fallbackModel) {
|
||||
logger.warn(`[CloudCode] All accounts exhausted for ${model}. Attempting fallback to ${fallbackModel}`);
|
||||
// Retry with fallback model
|
||||
const fallbackRequest = { ...anthropicRequest, model: fallbackModel };
|
||||
return await sendMessage(fallbackRequest, accountManager, false); // Disable fallback for recursive call
|
||||
}
|
||||
}
|
||||
throw new Error('No accounts available');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user