From 5ed8fb47aaa7dea59df69c583c54ad94fc7bbcfd Mon Sep 17 00:00:00 2001 From: SeongBeomLEE <2712qwer@gmail.com> Date: Sat, 8 Feb 2025 20:33:44 +0900 Subject: [PATCH 1/2] [fix] Problems with overlapping specific turns when generating LLM final answers --- ui/components/ChatWindow.tsx | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index b26573f..e65c5e0 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -413,6 +413,8 @@ const ChatWindow = ({ id }: { id?: string }) => { const [isMessagesLoaded, setIsMessagesLoaded] = useState(false); + const [pendingRewrite, setPendingRewrite] = useState<{ content: string; messageId: string } | null>(null); + const [notFound, setNotFound] = useState(false); const [isSettingsOpen, setIsSettingsOpen] = useState(false); @@ -452,6 +454,12 @@ const ChatWindow = ({ id }: { id?: string }) => { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + const chatHistoryRef = useRef<[string, string][]>([]); + + useEffect(() => { + chatHistoryRef.current = chatHistory; + }, [chatHistory]); + const messagesRef = useRef([]); useEffect(() => { @@ -494,7 +502,7 @@ const ChatWindow = ({ id }: { id?: string }) => { files: fileIds, focusMode: focusMode, optimizationMode: optimizationMode, - history: [...chatHistory, ['human', message]], + history: [...chatHistoryRef.current], }), ); @@ -609,15 +617,22 @@ const ChatWindow = ({ id }: { id?: string }) => { const message = messages[index - 1]; setMessages((prev) => { - return [...prev.slice(0, messages.length > 2 ? index - 1 : 0)]; + return [...prev.slice(0, messages.length >= 2 ? index - 1 : 0)]; }); setChatHistory((prev) => { - return [...prev.slice(0, messages.length > 2 ? index - 1 : 0)]; + return [...prev.slice(0, messages.length >= 2 ? index - 1 : 0)]; }); - sendMessage(message.content, message.messageId); + setPendingRewrite({content: message.content, messageId: message.messageId}); }; + useEffect(() => { + if (pendingRewrite) { + sendMessage(pendingRewrite.content, pendingRewrite.messageId); + setPendingRewrite(null); + } + }, [chatHistory]); + useEffect(() => { if (isReady && initialMessage && ws?.readyState === 1) { sendMessage(initialMessage); From 80ac0c92ba32d6d43b8958a5df8713dea709a052 Mon Sep 17 00:00:00 2001 From: SeongBeomLEE <2712qwer@gmail.com> Date: Sat, 8 Feb 2025 21:22:10 +0900 Subject: [PATCH 2/2] [fix] Change useEffect dependence --- ui/components/ChatWindow.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/components/ChatWindow.tsx b/ui/components/ChatWindow.tsx index e65c5e0..c34806a 100644 --- a/ui/components/ChatWindow.tsx +++ b/ui/components/ChatWindow.tsx @@ -631,7 +631,7 @@ const ChatWindow = ({ id }: { id?: string }) => { sendMessage(pendingRewrite.content, pendingRewrite.messageId); setPendingRewrite(null); } - }, [chatHistory]); + }, [pendingRewrite]); useEffect(() => { if (isReady && initialMessage && ws?.readyState === 1) {