Bug-session_state

Summary

NoneType object not callable for session_state object. How to fix it?

I made an LLM chatbot, installed all the required modules but for some reason this error keeps showing up. I assume it is because session_state is missing?
Code snippet:

def handle_userinput(user_question):
    response = st.session_state.conversation({'question': user_question})
    st.session_state.chat_history = response['chat_history']

    for i, message in enumerate(st.session_state.chat_history):
        if i % 2 == 0:
            st.write(user_template.replace(
                "{{MSG}}", message.content), unsafe_allow_html=True)
        else:
            st.write(bot_template.replace(
                "{{MSG}}", message.content), unsafe_allow_html=True)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:
I expect the session_state object to work and use the required methods

Actual behavior:

Debug info

langchain==0.0.184

PyPDF2==3.0.1

python-dotenv==1.0.0

streamlit==1.18.1

openai==0.27.6

faiss-cpu==1.7.4

python=3.11.1

uncomment to use huggingface llms

huggingface-hub==0.14.1

uncomment to use instructor embeddings

InstructorEmbedding==1.0.1

sentence-transformers==2.2.2

Requirements file

(App dependencies - Streamlit Docs) and add a requirements file to your app.

Links

Additional information

If needed, add any other context about the problem here.

No, it is because st.session_state.conversation is None.

What to do about it then? other than re installing streamlit.

The bug is most likely in your code, reinstalling streamlit will not fix it.

If you think st.session_state.conversation should never be None, then make sure it is never None.

If st.session_state.conversation should be None sometimes, then make sure you don’t call it in those cases.

If you want people to help you debugging your code, fix the link to your repo, right now it is broken.

Oh my bad, I fixed the link.
Okay got it.

At the beginning you assign None to st.session_state.conversation. You cannot call it until you assign a different (callable) value.

Okay Thankyou