From 1895b2e8b72ee29204fbce37824c3dd96849bf21 Mon Sep 17 00:00:00 2001 From: ericcccliu Date: Fri, 29 Mar 2024 14:42:31 -0500 Subject: [PATCH] fix first message bug --- app/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/utils.ts b/app/utils.ts index d2fb6e8..a9991e7 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -111,7 +111,6 @@ export const handleSendMessage = async ( role: "user", content: textValue, }; - setMessages((prevMessages) => [...prevMessages, newMessage]); setTextValue(""); if (!conversationId) { @@ -134,6 +133,7 @@ export const handleSendMessage = async ( if (response.ok) { const data = await response.json(); setConversationId(data.conversation_id); + // Send the new message to the newly created conversation const messageResponse = await fetch( @@ -151,11 +151,14 @@ export const handleSendMessage = async ( ); if (messageResponse.ok) { + setMessages((prevMessages) => prevMessages.length === 0 ? [...prevMessages, newMessage] : [...prevMessages]); await handleStreamingResponse(messageResponse, setMessages); } } } else { // Add message to existing conversation + setMessages((prevMessages) => [...prevMessages, newMessage]); + const response = await fetch( `${process.env.BACKEND_URL}/conversations/${conversationId}/message`, {