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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.