Skip to content

Commit

Permalink
fix: Fix an issue with simulating bot and user message
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Nov 3, 2024
1 parent a4104d8 commit 2ff276e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/hooks/internal/useMessagesInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ export const useMessagesInternal = () => {
// stop bot typing when simulating stream
setIsBotTyping(false);

// set an initial empty message to be used for streaming
setMessages(prevMessages => {
const updatedMessages = [...prevMessages, message];
handlePostMessagesUpdate(updatedMessages);
return updatedMessages;
});
streamMessageMap.current.set("bot", message.id);
if (!streamMessageMap.current.has(message.sender)) {
// set an initial empty message to be used for streaming
setMessages(prevMessages => {
const updatedMessages = [...prevMessages, createMessage("", message.sender)];
handlePostMessagesUpdate(updatedMessages);
return updatedMessages;
});
streamMessageMap.current.set(message.sender, message.id);
}

// initialize default message to empty with stream index position 0
let streamMessage = message.content as string | string[];
Expand Down Expand Up @@ -100,7 +102,7 @@ export const useMessagesInternal = () => {
});

await simStreamDoneTask;
streamMessageMap.current.delete("bot");
streamMessageMap.current.delete(message.sender);
saveChatHistory(messages);
}, [messages, streamMessageMap]);

Expand Down

0 comments on commit 2ff276e

Please sign in to comment.