From ffd2d1a2910d4b5ce193e9479d1203118bf67c67 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 Feb 2026 21:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=87=AA=E5=8A=A8=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E9=BB=98=E8=AE=A4=E6=A8=A1=E5=9E=8B=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ai/model-router.ts | 54 +++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/ai/model-router.ts b/lib/ai/model-router.ts index df0b793..5985503 100644 --- a/lib/ai/model-router.ts +++ b/lib/ai/model-router.ts @@ -116,30 +116,6 @@ export async function routeToModel(params: { // 获取所有可用模型 const allModels = await getEnabledAiModelsWithProvider(); console.log("[Model Router] Available models:", allModels.length); - - // 🆕 检查是否有配置的默认生图模型 - const [settings] = await db.select().from(siteSettings).limit(1); - const configuredDefaultModelId = settings?.canvasAutoModeDefaultModelId; - - if (configuredDefaultModelId) { - // 如果配置了默认模型,直接使用该模型 - const configuredModel = allModels.find( - (m) => m.model.id === configuredDefaultModelId && m.model.isEnabled && !m.model.isSubModel - ); - - if (configuredModel) { - console.log("[Model Router] ✅ Using configured default model:", configuredModel.model.displayName); - return { - id: configuredModel.model.id, - displayName: configuredModel.model.displayName, - providerType: configuredModel.provider.type, - modelId: configuredModel.model.modelId, - reason: `管理员配置的默认模型 → ${configuredModel.model.displayName}`, - }; - } else { - console.log("[Model Router] ⚠️ Configured default model not found or disabled, falling back to intent routing"); - } - } // 获取意图对应的配置 let config = INTENT_MODEL_MAP[intent] || INTENT_MODEL_MAP["chat"]; @@ -152,6 +128,36 @@ export async function routeToModel(params: { } } + // 🆕 检查是否有配置的默认生图模型(仅在能力匹配时使用) + const [settings] = await db.select().from(siteSettings).limit(1); + const configuredDefaultModelId = settings?.canvasAutoModeDefaultModelId; + + if (configuredDefaultModelId) { + const configuredModel = allModels.find( + (m) => m.model.id === configuredDefaultModelId && m.model.isEnabled && !m.model.isSubModel + ); + + if (configuredModel) { + const matchesVision = !config.requireVision || configuredModel.model.supportsVision; + const matchesImageGen = !config.requireImageGen || configuredModel.model.supportsImageGen; + + if (matchesVision && matchesImageGen) { + console.log("[Model Router] ✅ Using configured default model:", configuredModel.model.displayName); + return { + id: configuredModel.model.id, + displayName: configuredModel.model.displayName, + providerType: configuredModel.provider.type, + modelId: configuredModel.model.modelId, + reason: `管理员配置的默认模型 → ${configuredModel.model.displayName}`, + }; + } + + console.log("[Model Router] ⚠️ Configured default model does not match intent requirements, falling back"); + } else { + console.log("[Model Router] ⚠️ Configured default model not found or disabled, falling back to intent routing"); + } + } + // 按优先级查找匹配的模型 for (const providerType of config.providerTypes) { const candidates = allModels.filter((m) => {