Skip to content

Commit

Permalink
fix first message bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ericcccsliu committed Mar 29, 2024
1 parent 62897db commit 1895b2e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export const handleSendMessage = async (
role: "user",
content: textValue,
};
setMessages((prevMessages) => [...prevMessages, newMessage]);
setTextValue("");

if (!conversationId) {
Expand All @@ -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(
Expand All @@ -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`,
{
Expand Down

0 comments on commit 1895b2e

Please sign in to comment.