Markdown code appears above title when clearing chat history

Summary

After adding the if statement in my clear chat history function, I now see some markdown code above the title as shown (i.e. None) This is after pressing the button:

What I’m trying to do is update a doc in firestore whenever logged in users clear their own chat history. The markdown also appears when logged in or not.

Steps to reproduce

Code snippet:

def clear():
    st.session_state.chat_history = [{""}] #left blank intentionally
    if 'user_id' in st.session_state:
        st.session_state.get('user_id') and db.collection("users").document(st.session_state.user_id.replace(
        "/", "-")).update({"chat_history": st.session_state.chat_history})

Expected behavior:

No markdown code should appear above the title.

Actual behavior:

Before adding that line of markdown code the code above the title never appeared when clearing chat history. I’m trying to not have the app crash when it tries to find the user_id whenever they’re logged in or not.

Debug info

  • Streamlit version: 1.26.0
  • Python version: 3.10.12
  • OS version: EC2 Ubuntu 23.04
  • Browser version: Chrome 116.0.5845.179

Links

  • Link to your deployed app: App

Removing the if statement should solve the issue.

Yes removing the whole if statement would remove the markdown, but I still need to update a user doc in firestore. Do I remove the if, but keep the rest of the code below it?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.