Fix useRef typo and update chat message reference
This commit is contained in:
parent
3c56b7a2b7
commit
42338a829b
2 changed files with 41 additions and 37 deletions
|
|
@ -32,6 +32,13 @@ export default function ChatMessage({
|
||||||
const [isStreaming, setIsStreaming] = useState(false);
|
const [isStreaming, setIsStreaming] = useState(false);
|
||||||
const eventSource = useRef<EventSource | undefined>(undefined);
|
const eventSource = useRef<EventSource | undefined>(undefined);
|
||||||
const updateFlowPool = useFlowStore((state) => state.updateFlowPool);
|
const updateFlowPool = useFlowStore((state) => state.updateFlowPool);
|
||||||
|
const chatMessageRef = useRef(chatMessage);
|
||||||
|
|
||||||
|
// Sync ref with state
|
||||||
|
useEffect(() => {
|
||||||
|
chatMessageRef.current = chatMessage;
|
||||||
|
}, [chatMessage]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The idea now is that chat.stream_url MAY be a URL if we should stream the output of the chat
|
// The idea now is that chat.stream_url MAY be a URL if we should stream the output of the chat
|
||||||
|
|
@ -63,15 +70,13 @@ export default function ChatMessage({
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(streamUrl)
|
console.log("chatMessage", chatMessage);
|
||||||
if (streamUrl && !isStreaming) {
|
if (streamUrl && !isStreaming) {
|
||||||
streamChunks(streamUrl)
|
streamChunks(streamUrl)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (updateChat) {
|
if (updateChat) {
|
||||||
console.log("rodou")
|
updateChat(chat, chatMessageRef.current);
|
||||||
updateChat(chat, chatMessage);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,6 @@ export default function NewChatView({
|
||||||
) {
|
) {
|
||||||
if (message === "") return;
|
if (message === "") return;
|
||||||
chat.message = message;
|
chat.message = message;
|
||||||
console.log(message)
|
|
||||||
// chat is one of the chatHistory
|
// chat is one of the chatHistory
|
||||||
updateFlowPool(chat.componentId,{message,sender_name:chat.sender_name??"Bot",sender:"Machine"})
|
updateFlowPool(chat.componentId,{message,sender_name:chat.sender_name??"Bot",sender:"Machine"})
|
||||||
// setChatHistory((oldChatHistory) => {
|
// setChatHistory((oldChatHistory) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue