import { useEffect, useRef } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import Hero from '../Hero'; import { AppDispatch } from '../store'; import ConversationBubble from './ConversationBubble'; import { addMessage, fetchAnswer, selectConversation, selectStatus, } from './conversationSlice'; import Send from './../assets/send.svg'; import Spinner from './../assets/spinner.svg'; export default function Conversation() { const messages = useSelector(selectConversation); const status = useSelector(selectStatus); const dispatch = useDispatch(); const endMessageRef = useRef(null); const inputRef = useRef(null); useEffect(() => endMessageRef?.current?.scrollIntoView({ behavior: 'smooth' }), ); const handleQuestion = (question: string) => { dispatch(addMessage({ text: question, type: 'QUESTION' })); dispatch(fetchAnswer({ question })); }; return (
{messages.map((message, index) => { return ( ); })} {messages.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) { handleQuestion(inputRef.current.textContent); inputRef.current.textContent = ''; } }} src={Send} className="relative right-9 cursor-pointer" > )}

This is a chatbot that uses the GPT-3, Faiss and LangChain to answer questions.

); }