fix image failover eligibility
This commit is contained in:
parent
1947aae685
commit
edae2f83c2
@ -133,6 +133,7 @@ import { saveGeneratedImages } from "@/lib/ai/runtime/generated-image-persistenc
|
||||
import {
|
||||
recordAiModelHealthFailure,
|
||||
recordAiModelHealthSuccess,
|
||||
shouldFailoverAiModelError,
|
||||
} from "@/lib/ai/runtime/model-health";
|
||||
import type { FalImageEditTaskMetadata } from "@/lib/ai/runtime/fal-image-edit-task";
|
||||
import { saveAssistantTextOnlyMessage } from "@/lib/ai/runtime/assistant-message-persistence";
|
||||
@ -6405,6 +6406,11 @@ export async function POST(request: Request) {
|
||||
}).catch((healthError) => {
|
||||
chatApiLogger.warn("[Chat API] Record Gemini primary health failure failed:", healthError);
|
||||
});
|
||||
|
||||
if (!shouldFailoverAiModelError(primaryError)) {
|
||||
chatApiLogger.info("[Chat API] Gemini primary error is not eligible for image failover; returning original error.");
|
||||
throw primaryError;
|
||||
}
|
||||
|
||||
// 🆕 尝试备用模型(支持跨服务商切换)
|
||||
let fallbackSuccess = false;
|
||||
@ -7115,6 +7121,11 @@ export async function POST(request: Request) {
|
||||
imageMarkdown = await tryGenerateImage(actualModelId, false);
|
||||
} catch (primaryError) {
|
||||
chatApiLogger.error("[Chat API] Alibaba primary model failed:", primaryError);
|
||||
|
||||
if (!shouldFailoverAiModelError(primaryError)) {
|
||||
chatApiLogger.info("[Chat API] Alibaba primary error is not eligible for image failover; returning original error.");
|
||||
throw primaryError;
|
||||
}
|
||||
|
||||
let fallbackSuccess = false;
|
||||
for (const candidate of fallbackCandidates) {
|
||||
@ -7530,6 +7541,10 @@ export async function POST(request: Request) {
|
||||
imageMarkdown = await tryGenerateImage(actualModelId, false);
|
||||
} catch (primaryError) {
|
||||
chatApiLogger.error("[Chat API] Volcano primary model failed:", primaryError);
|
||||
if (!shouldFailoverAiModelError(primaryError)) {
|
||||
chatApiLogger.info("[Chat API] Volcano primary error is not eligible for image failover; returning original error.");
|
||||
throw primaryError;
|
||||
}
|
||||
let fallbackSuccess = false;
|
||||
for (const candidate of fallbackCandidates) {
|
||||
try {
|
||||
@ -8361,6 +8376,11 @@ export async function POST(request: Request) {
|
||||
normalizedText = await tryGenerateWithOpenAICompatModel(languageModel);
|
||||
} catch (primaryError) {
|
||||
chatApiLogger.error("[Chat API] OpenAI-compatible primary model failed:", primaryError);
|
||||
|
||||
if (!shouldFailoverAiModelError(primaryError)) {
|
||||
chatApiLogger.info("[Chat API] OpenAI-compatible primary error is not eligible for image failover; returning original error.");
|
||||
throw primaryError;
|
||||
}
|
||||
|
||||
let fallbackSuccess = false;
|
||||
for (const candidate of fallbackCandidates) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user