Skip to content

Commit 436fc76

Browse files
websocket nesting issue fixed
1 parent 56dd582 commit 436fc76

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

components/Chat/Chat.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,12 @@ export const Chat = () => {
267267
// if this is the first message (of the assistant response to user message), then add the message to the conversation as 'assistant' message
268268
// else append the message to the exisiting assistant message (part of the stream appending)
269269
// look through the conversation messages and find if a assistant message has id = parentId
270-
const assistantMessage = selectedConversation?.messages?.find((msg) => msg.role === 'assistant' && msg.parentId === message?.parent_id)
271-
if(assistantMessage) {
270+
const isLastMessageFromAssistant = selectedConversation?.messages[selectedConversation?.messages?.length - 1].role === 'assistant'
271+
if(isLastMessageFromAssistant) {
272272
// console.log('found assistant message, appending to it')
273273
// update the assistant message inside selectedConversation
274-
updatedMessages = selectedConversation?.messages?.map((msg) => {
275-
if (msg.role === 'assistant' && msg.parentId === message?.parent_id) {
274+
updatedMessages = selectedConversation?.messages?.map((msg, idx) => {
275+
if (msg.role === 'assistant' && idx === selectedConversation?.messages?.length - 1) {
276276
// do this only for response token
277277
let updatedContent = msg.content || '';
278278
if(message?.type === webSocketMessageTypes.systemResponseMessage) {

0 commit comments

Comments
 (0)