修正自动模式默认模型匹配

This commit is contained in:
Your Name 2026-02-05 21:53:36 +08:00
parent 66458e97fb
commit ffd2d1a291

View File

@ -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) => {