Add a “history_list” variable to webui_pages/dialogue/dialogue.py in the Langchain-Chatchat repository and on clicking the button at “col[1]” clear its value.
Steps to reproduce
Code snippet:
...
# outside the function
if 'history_list' not in st.session_state:
st.session_state['history_list'] = []
...
# add something to history_list[]
...
#
# The last few lines in the dialogue.py code in the function dialogue_page():
with st.sidebar:
cols = st.columns(2)
export_btn = cols[0]
if cols[1].button(
"清空对话",
use_container_width=True,
):
chat_box.reset_history()
st.experimental_rerun()
st.session_state['history_list'] = []
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
When I click on this button, the “history_list” should be cleared out.
Thank you very much for your help :). I apologise, this doesn’t seem to work in my code. I also found that this function works differently in different positions, this I wonder if this can be used as a kind of inspiration for you?
with st.sidebar:
def clear_chat_history():
if "history_list" in st.session_state:
print("clean history_list!")
st.session_state.history_list = []
cols = st.columns(2)
export_btn = cols[0]
if cols[1].button(
"清空对话",
use_container_width=True,
):
chat_box.reset_history()
st.experimental_rerun()
Under this position, the value of “history_list” is always empty, whether I press that button or not.
def clear_chat_history():
if "history_list" in st.session_state:
print("clean history_list!")
st.session_state.history_list = []
with st.sidebar:
cols = st.columns(2)
export_btn = cols[0]
if cols[1].button(
"清空对话",
use_container_width=True,
):
chat_box.reset_history()
st.experimental_rerun()
If it’s outside the “st.sidebar”, then it won’t work when the button is clicked.