From 2f9cbe2bf112d2b357eaea7779e65d82b61e9234 Mon Sep 17 00:00:00 2001 From: utin-francis-peter Date: Tue, 11 Jun 2024 20:30:12 +0100 Subject: [PATCH] chore: if user types in a new prompt after failed generation (instead of hitting retry btn), the failed query is updated with the new prompt before response is fetched. Ensuring every query object remains useful & relevant --- frontend/src/conversation/Conversation.tsx | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 1695f714..8d221570 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -33,6 +33,8 @@ export default function Conversation() { const [lastQueryReturnedErr, setLastQueryReturnedErr] = useState(false); const { t } = useTranslation(); + console.log('QUERIES: ', queries); + const handleUserInterruption = () => { if (!eventInterrupt && status === 'loading') setEventInterrupt(true); }; @@ -102,6 +104,7 @@ export default function Conversation() { !isRetry && dispatch(addQuery({ prompt: question })); //dispatch only new queries fetchStream.current = dispatch(fetchAnswer({ question })); }; + const handleFeedback = (query: Query, feedback: FEEDBACK, index: number) => { const prevFeedback = query.feedback; dispatch(updateQuery({ index, query: { feedback } })); @@ -110,6 +113,29 @@ export default function Conversation() { ); }; + const handleQuestionSubmission = () => { + if (inputRef.current?.textContent && status !== 'loading') { + if (lastQueryReturnedErr) { + // update last failed query with new prompt + dispatch( + updateQuery({ + index: queries.length - 1, + query: { + prompt: inputRef.current.textContent, + }, + }), + ); + handleQuestion({ + question: queries[queries.length - 1].prompt, + isRetry: true, + }); + } else { + handleQuestion({ question: inputRef.current.textContent }); + } + inputRef.current.textContent = ''; + } + }; + const prepResponseView = (query: Query, index: number) => { let responseView; if (query.response) { @@ -196,12 +222,12 @@ export default function Conversation() {