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 {
|
import {
|
||||||
recordAiModelHealthFailure,
|
recordAiModelHealthFailure,
|
||||||
recordAiModelHealthSuccess,
|
recordAiModelHealthSuccess,
|
||||||
|
shouldFailoverAiModelError,
|
||||||
} from "@/lib/ai/runtime/model-health";
|
} from "@/lib/ai/runtime/model-health";
|
||||||
import type { FalImageEditTaskMetadata } from "@/lib/ai/runtime/fal-image-edit-task";
|
import type { FalImageEditTaskMetadata } from "@/lib/ai/runtime/fal-image-edit-task";
|
||||||
import { saveAssistantTextOnlyMessage } from "@/lib/ai/runtime/assistant-message-persistence";
|
import { saveAssistantTextOnlyMessage } from "@/lib/ai/runtime/assistant-message-persistence";
|
||||||
@ -6406,6 +6407,11 @@ export async function POST(request: Request) {
|
|||||||
chatApiLogger.warn("[Chat API] Record Gemini primary health failure failed:", 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;
|
let fallbackSuccess = false;
|
||||||
const triedFallbackModelIds = new Set<string>();
|
const triedFallbackModelIds = new Set<string>();
|
||||||
@ -7116,6 +7122,11 @@ export async function POST(request: Request) {
|
|||||||
} catch (primaryError) {
|
} catch (primaryError) {
|
||||||
chatApiLogger.error("[Chat API] Alibaba primary model failed:", 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;
|
let fallbackSuccess = false;
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
try {
|
try {
|
||||||
@ -7530,6 +7541,10 @@ export async function POST(request: Request) {
|
|||||||
imageMarkdown = await tryGenerateImage(actualModelId, false);
|
imageMarkdown = await tryGenerateImage(actualModelId, false);
|
||||||
} catch (primaryError) {
|
} catch (primaryError) {
|
||||||
chatApiLogger.error("[Chat API] Volcano primary model failed:", 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;
|
let fallbackSuccess = false;
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
try {
|
try {
|
||||||
@ -8362,6 +8377,11 @@ export async function POST(request: Request) {
|
|||||||
} catch (primaryError) {
|
} catch (primaryError) {
|
||||||
chatApiLogger.error("[Chat API] OpenAI-compatible primary model failed:", 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;
|
let fallbackSuccess = false;
|
||||||
for (const candidate of fallbackCandidates) {
|
for (const candidate of fallbackCandidates) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user