From 409fac546103a0bbe5566cfad6bdcdfabf3c941f Mon Sep 17 00:00:00 2001 From: Ethan-Zhang Date: Thu, 20 Nov 2025 23:39:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20=E4=BB=8Ellm=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=9B=B4=E6=8E=A5=E8=8E=B7=E5=8F=96=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E8=83=BD=E5=8A=9B=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialogue/components/DialogueSession.vue | 119 ++++++++++++------ 1 file changed, 80 insertions(+), 39 deletions(-) diff --git a/src/views/dialogue/components/DialogueSession.vue b/src/views/dialogue/components/DialogueSession.vue index aa7f4af..657844e 100644 --- a/src/views/dialogue/components/DialogueSession.vue +++ b/src/views/dialogue/components/DialogueSession.vue @@ -972,6 +972,62 @@ const clearSuggestion = (index: number): void => { } }; +// 🔑 优化:获取完整的模型信息(包括能力字段) +// 优先从已加载的 llmOptions 中查找,避免重复请求 +const getFullModelInfo = async (llmId: string): Promise => { + // 🔑 优先级1:从已加载的 llmOptions 中查找 + if (llmOptions.value && llmOptions.value.length > 0) { + const foundModel = llmOptions.value.find(model => + (model.llmId || model.id) === llmId + ); + + if (foundModel) { + return { + llmId: foundModel.llmId, + id: foundModel.id || foundModel.llmId, + modelName: foundModel.modelName, + icon: foundModel.icon || '', + supportsThinking: foundModel.supportsThinking, + canToggleThinking: foundModel.canToggleThinking + } as LLMOption; + } + } + + // 🔑 优先级2:如果 llmOptions 为空或未找到,才调用 API 查询 + try { + const [_, res] = await api.getLLMList({ type: 'chat' }); + if (!_ && res && res.code === 200) { + const allModels = res.result || []; + const chatModels = allModels.filter(model => { + if (!model.type) return true; + if (Array.isArray(model.type)) { + return model.type.includes('chat'); + } + return model.type === 'chat'; + }); + + // 查找匹配的模型 + const foundModel = chatModels.find(model => + (model.llmId || model.id) === llmId + ); + + if (foundModel) { + return { + llmId: foundModel.llmId, + id: foundModel.id || foundModel.llmId, + modelName: foundModel.modelName, + icon: foundModel.icon || '', + supportsThinking: foundModel.supportsThinking, + canToggleThinking: foundModel.canToggleThinking + } as LLMOption; + } + } + } catch (error) { + console.error('获取模型信息失败', error); + } + return null; +}; + // 🔑 修复:添加 forceReselect 参数,确保每次页面进入都能重新选择模型 const getProviderLLM = async (forceReselect: boolean = false) => { // 🔑 修复:使用查询参数type限制只查询chat类型的模型 @@ -1012,19 +1068,17 @@ const getProviderLLM = async (forceReselect: boolean = false) => { currentSession.llm && currentSession.llm.llmId && conversationList.value.length > 0) { - // 🔑 已存在对话:使用历史记录中的模型 - const historicalModel = llmOptions.value.find(model => - (model.llmId || model.id) === currentSession.llm.llmId - ); + // 🔑 优化方案:优先从 llmOptions 查找,避免重复 API 请求 + const fullModel = await getFullModelInfo(currentSession.llm.llmId); - if (historicalModel) { + if (fullModel) { selectedLLM.value = { - llmId: historicalModel.llmId || historicalModel.id, - id: historicalModel.id || historicalModel.llmId, - modelName: historicalModel.modelName, - icon: historicalModel.icon || '', - supports_thinking: historicalModel.supportsThinking || false, - can_toggle_thinking: historicalModel.canToggleThinking || false + llmId: fullModel.llmId || fullModel.id, + id: fullModel.id || fullModel.llmId, + modelName: fullModel.modelName, + icon: fullModel.icon || '', + supports_thinking: fullModel.supportsThinking || false, + can_toggle_thinking: fullModel.canToggleThinking || false }; return; // 找到历史模型,直接返回 } @@ -1302,7 +1356,7 @@ watch( // 🔑 恢复:监听 selectLLM 变化,但添加条件判断 // 只有当会话有对话记录时才应用历史模型,新对话使用用户偏好模型 -watch(selectLLM, (newValue) => { +watch(selectLLM, async (newValue) => { // 🔑 条件判断: // 1. newValue 必须有值且有ID // 2. 当前没有选中模型(避免覆盖用户手动选择) @@ -1312,34 +1366,21 @@ watch(selectLLM, (newValue) => { !selectedLLM.value && conversationList.value.length > 0) { - // 🔑 关键修复:如果是从历史记录来的,需要从llmOptions中查找完整的模型信息 - // 确保包含 supports_thinking 等能力字段 - if (newValue._fromHistory && llmOptions.value.length > 0) { - const llmId = newValue.llmId || newValue.id; - const fullModel = llmOptions.value.find(model => - (model.llmId || model.id) === llmId - ); - - if (fullModel) { - selectedLLM.value = { - llmId: fullModel.llmId || fullModel.id, - id: fullModel.id || fullModel.llmId, - modelName: fullModel.modelName || '', - icon: fullModel.icon || '', - supports_thinking: fullModel.supportsThinking || false, - can_toggle_thinking: fullModel.canToggleThinking || false - }; - } else { - selectedLLM.value = { - llmId: newValue.llmId || newValue.id, - id: newValue.id || newValue.llmId, - modelName: newValue.modelName || '', - icon: newValue.icon || '', - supports_thinking: newValue.supportsThinking || false, - can_toggle_thinking: newValue.canToggleThinking || false - }; - } + // 🔑 优化方案:优先从 llmOptions 查找完整信息,避免重复 API 请求 + const llmId = newValue.llmId || newValue.id; + const fullModel = await getFullModelInfo(llmId); + + if (fullModel) { + selectedLLM.value = { + llmId: fullModel.llmId || fullModel.id, + id: fullModel.id || fullModel.llmId, + modelName: fullModel.modelName || '', + icon: fullModel.icon || '', + supports_thinking: fullModel.supportsThinking || false, + can_toggle_thinking: fullModel.canToggleThinking || false + }; } else { + // 如果查询失败,使用历史记录数据(可能缺少能力字段) selectedLLM.value = { llmId: newValue.llmId || newValue.id, id: newValue.id || newValue.llmId, -- Gitee From b2e235e2acf8503521cd2e639e180be64f2e8bd3 Mon Sep 17 00:00:00 2001 From: Ethan-Zhang Date: Thu, 20 Nov 2025 23:40:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/historySession.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/store/historySession.ts b/src/store/historySession.ts index 951dc19..edf08fb 100644 --- a/src/store/historySession.ts +++ b/src/store/historySession.ts @@ -158,7 +158,6 @@ export const useHistorySessionStore = defineStore( }; /** * 获取当前 llm 模型的数值 - * 🔑 修复:从完整的模型列表中查找,确保包含所有能力字段 */ const currentLLM = async () => { // 先置空 @@ -166,13 +165,7 @@ export const useHistorySessionStore = defineStore( await getHistorySession(); historySession.value.forEach((item) => { if (item.conversationId === currentSelectedSession.value) { - // 🔑 关键修复:不直接使用历史记录中的llm对象 - // 而是根据llmId从完整的模型列表中查找,确保包含所有能力字段 - selectLLM.value = { - ...item.llm, - // 标记这个是来自历史记录的,需要在使用时补充能力字段 - _fromHistory: true - }; + selectLLM.value = item.llm; if (item.appId) { app.value.appId = item.appId; } -- Gitee