Hello, I use streamlit authenticator and streamlit menu Create a dynamic navigation menu - Streamlit Docs
but different users shared session messages, below my code:
prompt_to_user=“How may I help you?”
if “messages” not in st.session_state.keys():
st.session_state.messages = [{“role”: “assistant”, “content”: prompt_to_user}]
Display chat messages
for message in st.session_state.messages:
if message[“role”] == “assistant”:
with st.chat_message(message[“role”], avatar=logo_path):
st.write(message[“content”])
else:
with st.chat_message(message[“role”], avatar=None):
st.write(message[“content”])
User-provided prompt
if prompt := st.chat_input():
st.session_state.messages.append({“role”: “user”, “content”: prompt})
with st.chat_message(“user”):
st.write(prompt)
Generate a new response if last message is not from assistant
if st.session_state.messages[-1][“role”] != “assistant”:
with st.chat_message(name=‘assistant’, avatar=logo_path):
with st.spinner(“Thinking…”):
response = rag_chain.invoke({“input”: prompt})
# save response in a text file
print(response, file=open(‘responses.txt’, ‘a’, encoding=‘utf-8’))
st.markdown(response[“answer”])
message = {“role”: “assistant”, “content”: response[“answer”]}
st.session_state.messages.append(message)