From 89f20567ce08f9c74eba8c84acf8078c8346e9cb Mon Sep 17 00:00:00 2001 From: Umberto Griffo <1609440+umbertogriffo@users.noreply.github.com> Date: Mon, 8 Jan 2024 19:13:00 +0000 Subject: [PATCH] fix: clear the chat history --- chatbot/chatbot_app.py | 2 +- chatbot/rag_chatbot_app.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/chatbot/chatbot_app.py b/chatbot/chatbot_app.py index 77ef3f8..4fed8fa 100644 --- a/chatbot/chatbot_app.py +++ b/chatbot/chatbot_app.py @@ -58,7 +58,7 @@ def init_welcome_message() -> None: def init_chat_history(conversational_retrieval: ConversationRetrieval) -> None: """ - Initialize chat history. + Initializes the chat history, allowing users to clear the conversation. """ clear_button = st.sidebar.button("Clear Conversation", key="clear") if clear_button or "messages" not in st.session_state: diff --git a/chatbot/rag_chatbot_app.py b/chatbot/rag_chatbot_app.py index 7777e32..fb05500 100644 --- a/chatbot/rag_chatbot_app.py +++ b/chatbot/rag_chatbot_app.py @@ -90,13 +90,14 @@ def init_welcome_message() -> None: st.write("How can I help you today?") -def init_messages() -> None: +def init_chat_history(conversational_retrieval: ConversationRetrieval) -> None: """ Initializes the chat history, allowing users to clear the conversation. """ clear_button = st.sidebar.button("Clear Conversation", key="clear") if clear_button or "messages" not in st.session_state: st.session_state.messages = [] + conversational_retrieval.get_chat_history().clear() def display_messages_from_history(): @@ -129,7 +130,7 @@ def main(parameters) -> None: conversational_retrieval = load_conversational_retrieval(_llm=llm) ctx_synthesis_strategy = load_ctx_synthesis_strategy(synthesis_strategy_name, _llm=llm) index = load_index(vector_store_path) - init_messages() + init_chat_history(conversational_retrieval) init_welcome_message() display_messages_from_history()