You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using react-simple-chatbot to create a chatbot that interacts with OpenAI to generate responses. I have implemented a custom component, SearchIA, to send the chat history and generate a response based on it. However, I am facing a problem where the chat history is empty in each new step, making it difficult to send a cumulative history for the chat.
Code Example:
// Code for Content componentconstContent=()=>{const[chatHistorySummary,setChatHistorySummary]=useState("");conststeps=[{id: '1',message: 'How can I help?',trigger: 'question'},{id: 'question',user: true,trigger: 'search'},{id: 'search',component: <SearchIAchatHistory={chatHistorySummary}setChatHistorySummary={setChatHistorySummary}/>,asMessage: true,trigger: 'question'}];return(<ThemeProvidertheme={theme}><ChatBotheaderTitle="Assistant"placeholder="Make a question..."steps={steps}/></ThemeProvider>);};exportdefaultContent;// Code for SearchIA componentconstSearchIA=({ steps, chatHistory, setChatHistorySummary})=>{const{ question, search }=steps;const[state,setState]=useState({
question,
search,response: ''});useEffect(()=>{constfetchData=async()=>{constsearchApiService=newSearchApiService();constmessage=state.question.value;letresp='';letcompletion='';if(message!==''){resp=awaitsearchApiService.sendMessage(message,chatHistory);completion=resp.completion;setChatHistorySummary(resp.chat_history_summary)}setState(prevState=>({
...prevState,response: completion}));};fetchData();},[state.question]);return(<div><p>{state.response}</p></div>);};exportdefaultSearchIA;```#### Expected Behavior:I expect the `SearchIA` component to receive the updated state of `chatHistorySummary` on each new step so that it can be sent to `SearchApiService`.#### Current Behavior:`SearchIA` is not receiving the new state. The `chatHistorySummary` state remains empty.#### Steps to Reproduce:1. Start a new conversation with the bot.2. The bot asks, "How can I help?"3. Enter a message.4. The bot displays a response.5. Enter a new message. You will notice that `chatHistorySummary` does not update.#### Possible Solution:I'm not sure what is causing this issue. Is there a way to share a variable (in this case, `chatHistorySummary`) from the `SearchIA` componenttoanewstepinthechat?
The text was updated successfully, but these errors were encountered:
braher
changed the title
Title: Issue with Keeping Chat History Across Steps in Custom Component
Issue with Keeping Chat History Across Steps in Custom Component
Sep 6, 2023
Chatbot keeps its own step context changes its data when iterating
you can simple make your const [chatHistorySummary, setChatHistorySummary] = useState("");
ARRAY and push each response and question const [chatHistorySummary, setChatHistorySummary] = useState([]);
Issue Description:
I am using
react-simple-chatbot
to create a chatbot that interacts with OpenAI to generate responses. I have implemented a custom component,SearchIA
, to send the chat history and generate a response based on it. However, I am facing a problem where the chat history is empty in each new step, making it difficult to send a cumulative history for the chat.Code Example:
The text was updated successfully, but these errors were encountered: