Deleting All Chats Before Every Refresh

Hello everyone,

Since Streamlit refreshes the front-end on every user interaction, I would like to clear all the messages before each refresh.

My app is a chatting bot, so sometimes it takes some time to answer the user, which causes a lag in the front-end, so if I deleted all the messages on the front-end it would be much better.

This is my code:

def print_conv():
    # Here I want to clear everything and reprint everything using the messages in session state
    for message in st.session_state.messages:
        try:
            st.write(message)
 

Thank you!