feat: Add button to remove messages and responses

This commit is contained in:
GOWxx
2023-03-31 22:55:49 +08:00
parent 61eb356fd9
commit 2ffe2a98b8
6 changed files with 69 additions and 27 deletions

View File

@@ -194,6 +194,7 @@ interface ChatStore {
summarizeSession: () => void;
updateStat: (message: Message) => void;
updateCurrentSession: (updater: (session: ChatSession) => void) => void;
removeMessage: (sessionIndex: number, messageIndex: number) => void;
updateMessage: (
sessionIndex: number,
messageIndex: number,
@@ -384,6 +385,15 @@ export const useChatStore = create<ChatStore>()(
return recentMessages;
},
removeMessage(sessionIndex: number, messageIndex: number) {
const sessions = get().sessions;
const session = sessions.at(sessionIndex);
const messages = session?.messages;
// remove user's message and bot's response
messages?.splice(messageIndex, 2);
set(() => ({ sessions }));
},
updateMessage(
sessionIndex: number,
messageIndex: number,