From 8d2ebe97187c42074df4782018af77f968497ba7 Mon Sep 17 00:00:00 2001 From: utin-francis-peter Date: Fri, 7 Jun 2024 15:59:56 +0100 Subject: [PATCH] feat: "Retry" btn conditionally renders in place of query input when a generation fails. Uses prev query to fetch answer when clicked. --- frontend/src/conversation/Conversation.tsx | 93 ++++++++++++++-------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 1bddf2e3..bda6b5f9 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -29,6 +29,7 @@ export default function Conversation() { const [hasScrolledToLast, setHasScrolledToLast] = useState(true); const fetchStream = useRef(null); const [eventInterrupt, setEventInterrupt] = useState(false); + const [lastQueryReturnedErr, setLastQueryReturnedErr] = useState(false); const { t } = useTranslation(); const handleUserInterruption = () => { @@ -73,6 +74,13 @@ export default function Conversation() { }; }, [endMessageRef.current]); + useEffect(() => { + if (queries.length) { + queries[queries.length - 1].error && setLastQueryReturnedErr(true); + queries[queries.length - 1].response && setLastQueryReturnedErr(false); //considering a query that initially returned error can later include a response property on retry + } + }, [queries]); + const scrollIntoView = () => { endMessageRef?.current?.scrollIntoView({ behavior: 'smooth', @@ -174,45 +182,60 @@ export default function Conversation() { {queries.length === 0 && }
-
-
{ - if (e.key === 'Enter' && !e.shiftKey) { - e.preventDefault(); - if (inputRef.current?.textContent && status !== 'loading') { - handleQuestion(inputRef.current.textContent); - inputRef.current.textContent = ''; - } - } - }} - >
- {status === 'loading' ? ( - - ) : ( -
- { - if (inputRef.current?.textContent) { + {!lastQueryReturnedErr ? ( +
+
{ + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + if (inputRef.current?.textContent && status !== 'loading') { handleQuestion(inputRef.current.textContent); inputRef.current.textContent = ''; } - }} - src={isDarkTheme ? SendDark : Send} + } + }} + >
+ {status === 'loading' ? ( + -
- )} -
+ ) : ( +
+ { + if (inputRef.current?.textContent) { + handleQuestion(inputRef.current.textContent); + inputRef.current.textContent = ''; + } + }} + src={isDarkTheme ? SendDark : Send} + > +
+ )} +
+ ) : ( +
+

There was an error during generation

+ +
+ )} +

{t('tagline')}