if st.session_state.messages[-1]["role"] != "assistant": with st.chat_message("assistant"): with st.spinner("Thinking..."): chat_engine=CondensePlusContextChatEngine.from_defaults(st.session_state.query_engine,memory=memory,system_prompt="You're a helpful and friendly chatbot that uses provided context to answer user queries. Context: {context_str}") response = chat_engine.chat(str(prompt)) history=memory.get() st.write(history) validating_prompt = (" Validate the provided response by ensuring it directly addresses the user's query or provides relevant information. Return False if the response does not contribute to answering the user's question." "Query: {query}" "Response: {bot_response}") feedback = llm.complete(validating_prompt.format(query=prompt,bot_response=response.response)) if feedback==False: st.write("DISTANCE APPROACH") response=answer_question(prompt) st.write(response) message = {"role": "assistant", "content": response} st.session_state.messages.append(message) else: st.write(response.response) message = {"role": "assistant", "content": response.response} st.session_state.messages.append(message)