Skip to content

Commit

Permalink
Remove user message and assistant message if present when updating cu…
Browse files Browse the repository at this point in the history
…rrent chat in useCurrentChat hook
  • Loading branch information
Royal-lobster committed Nov 26, 2023
1 parent 84480ac commit d845d7c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/hooks/useCurrentChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export const useCurrentChat = () => {
setMessages((p) => {
const index = p.findIndex((msg) => msg.timestamp === timestamp)
if (index === -1 || p[index].role !== ChatRole.USER) return p
p.splice(index, 2) // remove the user message and the assistant message
p.splice(index, 1) // remove user message
if (p[index] && p[index].role === ChatRole.ASSISTANT) {
// remove assistant message
p.splice(index, 1)
}
return [...p]
})
commitToStoredMessages()
Expand Down

0 comments on commit d845d7c

Please sign in to comment.