From 274930803ca4f5426986042002d255b7aa3151a3 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Tue, 4 Mar 2025 13:45:02 +0100 Subject: [PATCH] Cleanup --- src/components/thread/index.tsx | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/components/thread/index.tsx b/src/components/thread/index.tsx index 0280276..0b7d2f7 100644 --- a/src/components/thread/index.tsx +++ b/src/components/thread/index.tsx @@ -44,7 +44,7 @@ export function Thread() { const [input, setInput] = useState(""); const [firstTokenReceived, setFirstTokenReceived] = useState(false); const stream = useStreamContext(); - // const messages = [...dummyMessages, ...stream.messages]; + const messages = stream.messages; const isLoading = stream.isLoading; const prevMessageLength = useRef(0); @@ -71,23 +71,17 @@ export function Thread() { content: input, }; + const toolMessages = ensureToolCallsHaveResponses(stream.messages); stream.submit( - { - messages: [ - ...ensureToolCallsHaveResponses(stream.messages), - newHumanMessage, - ], - }, - { - streamMode: ["values"], - }, + { messages: [...toolMessages, newHumanMessage] }, + { streamMode: ["values"] } ); setInput(""); }; const handleRegenerate = ( - parentCheckpoint: Checkpoint | null | undefined, + parentCheckpoint: Checkpoint | null | undefined ) => { // Do this so the loading state is correct prevMessageLength.current = prevMessageLength.current - 1; @@ -100,14 +94,14 @@ export function Thread() { const chatStarted = isLoading || messages.length > 0; const renderMessages = messages.filter( - (m) => !m.id?.startsWith(DO_NOT_RENDER_ID_PREFIX), + (m) => !m.id?.startsWith(DO_NOT_RENDER_ID_PREFIX) ); return (
@@ -125,24 +119,24 @@ export function Thread() {
{renderMessages.map((message, index) => message.type === "human" ? ( ) : ( - ), + ) )} {isLoading && !firstTokenReceived && }
@@ -151,7 +145,7 @@ export function Thread() {
+