Skip to content

Commit

Permalink
🐛 fix: 修正 message parentId 不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jul 23, 2023
1 parent d511ca2 commit f86852a
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/store/session/slices/chat/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface ChatAction {
* @param messages - 聊天消息数组
* @param parentId - 父消息 ID,可选
*/
realFetchAIResponse: (messages: ChatMessage[], parentId?: string) => Promise<void>;
realFetchAIResponse: (messages: ChatMessage[], parentId: string) => Promise<void>;
/**
* 重新发送消息
* @param id - 消息 ID
Expand Down Expand Up @@ -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
Expand All @@ -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',
});
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f86852a

Please sign in to comment.