Skip to content

Commit

Permalink
Move the reset chat history button into the prompt interface
Browse files Browse the repository at this point in the history
  • Loading branch information
VioletVivirand committed May 22, 2024
1 parent 251eb1f commit e4fff3d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

# Display the sidebar
with st.sidebar:
# Reset Chat History button
if st.button("Reset Chat History", type="primary"):
st.session_state.messages = []
# st.experimental_rerun()
# # Reset Chat History button
# if st.button("Reset Chat History", type="primary"):
# st.session_state.messages = []
# # st.experimental_rerun()

# Credential configs
st.caption(body="Credential Configuration")
Expand Down Expand Up @@ -130,6 +130,11 @@
key="df_editor",
)

# Create a function to reset the chat history.
# This will be triggered by the clicking button at the end of Prompt Interface after everytime the prompt is sent
def reset_chat_history():
st.session_state.messages = []

# Prompt Interface
# Ref: https://docs.streamlit.io/knowledge-base/tutorials/build-conversational-apps#build-a-bot-that-mirrors-your-input
# Initialize chat history
Expand Down Expand Up @@ -216,6 +221,12 @@
st.error(error_msg, icon="🚨",)
print(error_msg)
st.session_state.messages = [] # If error occurs, remove all messages from history
finally:
# Always shows a Reset Chat History button at the bottom of the chat interface
with st.chat_message("Reset Controller", avatar="🤖"):
# Reset Chat History button
st.button("Reset Chat History", type="primary", on_click=reset_chat_history)


# Debug information
if st.query_params.get('debug') == "true":
Expand Down

0 comments on commit e4fff3d

Please sign in to comment.