From f86852a777aa9643b02b4b7a4301cad7b6249a54 Mon Sep 17 00:00:00 2001 From: arvinxx Date: Sun, 23 Jul 2023 20:24:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E4=BF=AE=E6=AD=A3=20mess?= =?UTF-8?q?age=20parentId=20=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/session/slices/chat/action.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/store/session/slices/chat/action.ts b/src/store/session/slices/chat/action.ts index 99c8ff51c989..f23a387709f9 100644 --- a/src/store/session/slices/chat/action.ts +++ b/src/store/session/slices/chat/action.ts @@ -50,7 +50,7 @@ export interface ChatAction { * @param messages - 聊天消息数组 * @param parentId - 父消息 ID,可选 */ - realFetchAIResponse: (messages: ChatMessage[], parentId?: string) => Promise; + realFetchAIResponse: (messages: ChatMessage[], parentId: string) => Promise; /** * 重新发送消息 * @param id - 消息 ID @@ -116,7 +116,7 @@ export const createChatSlice: StateCreator< set({ editingMessageId: messageId }); }, - realFetchAIResponse: async (messages: ChatMessage[], parentId?: string) => { + realFetchAIResponse: async (messages, userMessageId) => { const { dispatchMessage, generateMessage } = get(); // 添加 systemRole @@ -128,12 +128,11 @@ export const createChatSlice: StateCreator< // 再添加一个空的信息用于放置 ai 响应,注意顺序不能反 // 因为如果顺序反了,messages 中将包含新增的 ai message const assistantId = nanoid(); - const userId = parentId ?? nanoid(); dispatchMessage({ id: assistantId, message: LOADING_FLAT, - parentId: userId, + parentId: userMessageId, role: 'assistant', type: 'addMessage', }); @@ -209,7 +208,7 @@ export const createChatSlice: StateCreator< // 先拿到当前的 messages const messages = chatSelectors.currentChats(get()); - await realFetchAIResponse(messages); + await realFetchAIResponse(messages, userId); const chats = chatSelectors.currentChats(get()); if (chats.length >= 4) {