Skip to content

Commit 2680cde

Browse files
feat: add model isolation for tool calling (#672)
* feat: add model isolation for tool calling * feat: enhance chat model switching with history check and user confirmation
1 parent 891deff commit 2680cde

1 file changed

Lines changed: 55 additions & 11 deletions

File tree

src/views/chat/index.vue

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ function initLastToolResponseId() {
6464
return
6565
}
6666
}
67-
// 如果没有找到 editImageId,尝试使用最后一个 assistant 消息的 conversationOptions.parentMessageId
68-
// 只有当 parentMessageId 以 resp_ 开头时才使用
69-
for (let i = dataSources.value.length - 1; i >= 0; i--) {
70-
const chat = dataSources.value[i]
71-
const parentMessageId = chat.conversationOptions?.parentMessageId
72-
if (!chat.inversion && parentMessageId && parentMessageId.startsWith('resp_')) {
73-
lastToolResponseId.value = parentMessageId
74-
return
75-
}
76-
}
7767
// 如果都没有,清空
7868
lastToolResponseId.value = ''
7969
}
@@ -144,8 +134,13 @@ async function onConversation() {
144134
let options: Chat.ConversationRequest = {}
145135
const lastContext = conversationList.value[conversationList.value.length - 1]?.conversationOptions
146136
147-
if (lastContext && currentChatRoom.value?.usingContext)
137+
if (lastContext && currentChatRoom.value?.usingContext) {
148138
options = { ...lastContext }
139+
}
140+
else {
141+
// 如果当前对话没有使用上下文(新对话),清空 lastToolResponseId
142+
lastToolResponseId.value = ''
143+
}
149144
150145
await chatStore.addChatMessage(
151146
currentChatRoom.value!.roomId,
@@ -989,7 +984,56 @@ const footerClass = computed(() => {
989984
})
990985
991986
async function handleSyncChatModel(chatModel: string) {
987+
// 保存切换前的模型和 toolsEnabled 状态
988+
const previousModel = currentChatRoom.value?.chatModel
989+
const previousToolsEnabled = currentChatRoom.value?.toolsEnabled ?? false
990+
992991
await chatStore.setChatModel(chatModel)
992+
const newToolsEnabled = currentChatRoom.value?.toolsEnabled ?? false
993+
if (previousToolsEnabled !== newToolsEnabled) {
994+
// 检查当前房间是否有历史对话
995+
const hasHistory = dataSources.value.length > 0
996+
997+
// 如果没有历史对话,不弹窗提示,直接清空 lastToolResponseId
998+
if (!hasHistory) {
999+
lastToolResponseId.value = ''
1000+
return
1001+
}
1002+
1003+
// 有历史对话,弹出对话框询问是否新开会话
1004+
const d = dialog.warning({
1005+
title: '切换模型提示',
1006+
content: '检测到工具调用功能状态已变化,为避免混用,是否新开一个会话?',
1007+
positiveText: t('common.yes'),
1008+
negativeText: t('common.no'),
1009+
closable: false,
1010+
maskClosable: false,
1011+
onPositiveClick: async () => {
1012+
try {
1013+
if (previousModel) {
1014+
await chatStore.setChatModel(previousModel)
1015+
}
1016+
await chatStore.addNewChatRoom()
1017+
await chatStore.setChatModel(chatModel)
1018+
lastToolResponseId.value = ''
1019+
}
1020+
finally {
1021+
d.destroy()
1022+
}
1023+
},
1024+
onNegativeClick: async () => {
1025+
try {
1026+
// 用户选择不切换模型,回退到之前的模型
1027+
if (previousModel) {
1028+
await chatStore.setChatModel(previousModel)
1029+
}
1030+
}
1031+
finally {
1032+
d.destroy()
1033+
}
1034+
},
1035+
})
1036+
}
9931037
}
9941038
9951039
function handleUpdateMaxContextCount(maxContextCount: number) {

0 commit comments

Comments
 (0)