From 57ba73f6b605d8d0180264502e26c14db967a5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E4=BD=B3=E8=B1=AA?= Date: Thu, 15 Feb 2024 23:20:40 +0800 Subject: [PATCH] fix: fixed an issue where Tools intervention results were encountered when generating Conversation titles. --- src/chat.completion/ChatCompletionHandler.ts | 13 +++---------- src/components/ConversationBody.vue | 1 + src/components/MessageRecordItem.vue | 6 ++++++ src/openai/logic/services.ts | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/chat.completion/ChatCompletionHandler.ts b/src/chat.completion/ChatCompletionHandler.ts index a481c3f..f901a92 100644 --- a/src/chat.completion/ChatCompletionHandler.ts +++ b/src/chat.completion/ChatCompletionHandler.ts @@ -185,19 +185,13 @@ class ChatCompletionHandler { const messages: ChatCompletionMessage[] = [{ role: 'system', - content: 'You are a conversation summary assistant, you will generate a short title (10 characters or less) based on the user\'s conversation with you.', - tool_call_id: null, - tool_calls: null, - name: null, + content: 'You are a conversation summary assistant and you will generate a short title (10 characters or less) based on the conversation the user has with you. Generate the title in the language that the user is talking to you in.', }, { role: 'user', content: `The question for the dialogue is: ${messageInfo.user_content}`, - tool_call_id: null, - tool_calls: null, - name: null, - }] + }] as ChatCompletionMessage[] - const chatCompletionResponse = await openAIServices.createChatCompletionsRequest(messages, false) + const chatCompletionResponse = await openAIServices.createChatCompletionsRequest(messages, false, false) if (chatCompletionResponse.code !== 1 || chatCompletionResponse.data === null) return @@ -207,7 +201,6 @@ class ChatCompletionHandler { await ChatCompletionParser(chatCompletionResponse.data!, (text) => { title += text }, () => { }) - this.updateConversationTitleByIdAsync(title, messageInfo.conversation_id) } diff --git a/src/components/ConversationBody.vue b/src/components/ConversationBody.vue index e8992b9..c5e1d0b 100644 --- a/src/components/ConversationBody.vue +++ b/src/components/ConversationBody.vue @@ -63,6 +63,7 @@ function updateConversationInfo(newInfo: TBConverstationInfo) {
diff --git a/src/components/MessageRecordItem.vue b/src/components/MessageRecordItem.vue index ae23c17..df93ace 100644 --- a/src/components/MessageRecordItem.vue +++ b/src/components/MessageRecordItem.vue @@ -20,6 +20,7 @@ import getFunctionResultByFunctionName from '@/openai/handler/FunctionHandler' import messageController from '@/chat.completion/MessageController' const props = defineProps<{ + messageIndex: number messageInfo: TBMessageInfo scrollBody: () => void }>() @@ -96,6 +97,8 @@ async function getAnswer(messageId: number) { if (!needGetFunctionResult) { checkingFunctionCalling.value = false reloadMessageInfoFromDB() + if (props.messageIndex === 0) + chatCompletionStore.chatCompletionHandler?.getChatCompletionTitleFromMessageAsync(messageInfo.value.id) } } @@ -132,6 +135,9 @@ async function handleFunction(tool_call_id: string, functionName: string, args: if (result) reloadMessageInfoFromDB() + + if (props.messageIndex === 0) + chatCompletionStore.chatCompletionHandler?.getChatCompletionTitleFromMessageAsync(messageInfo.value.id) } /** diff --git a/src/openai/logic/services.ts b/src/openai/logic/services.ts index 9c184c1..525e590 100644 --- a/src/openai/logic/services.ts +++ b/src/openai/logic/services.ts @@ -34,7 +34,7 @@ class OpenAIServices { * @param useTools * @returns */ - public async createChatCompletionsRequest(message: ChatCompletionMessage[], useVisionAPI: boolean): Promise { + public async createChatCompletionsRequest(message: ChatCompletionMessage[], useVisionAPI: boolean, autoUseTools: boolean = true): Promise { const openAIPayload = await this.getOpenAIPayload() if (!openAIPayload) { @@ -54,7 +54,7 @@ class OpenAIServices { let fetchBody = null - if (tools && tools.length > 0) { + if (tools && tools.length > 0 && autoUseTools) { fetchBody = JSON.stringify({ top_p: topP.value, max_tokens: useVisionAPI ? gpt_models.find(item => item.value === usedModel)?.tokens : null,