I cannot get the chat functionality working when deploying to the community cloud and using authentication. Locally everything works as expected but the cloud exhibits strange behaviour.
Here is an example of the code that is not working on community cloud (but it does work locally):
import streamlit as st
import streamlit_authenticator as stauth
st.title("ChatGPT-like clone")
openai.api_key = st.secrets["OPENAI_API_KEY"]
authenticator = stauth.Authenticate(
dict(st.secrets['credentials']),
st.secrets['cookie']['name'],
st.secrets['cookie']['key'],
st.secrets['cookie']['expiry_days'],
st.secrets['preauthorized']
)
name, authentication_status, username = authenticator.login('Login', 'sidebar') # location is 'sidebar' or 'main'
if authentication_status:
if "openai_model" not in st.session_state:
st.session_state["openai_model"] = "gpt-3.5-turbo"
if "messages" not in st.session_state:
st.session_state.messages = []
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("What is up?"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
message_placeholder = st.empty()
full_response = ""
response = openai.chat.completions.create(
model=st.session_state["openai_model"],
messages=st.session_state.messages,
stream=True,
)
for part in response:
full_response += (part.choices[0].delta.content or "")
message_placeholder.markdown(full_response + "▌")
message_placeholder.markdown(full_response)
st.session_state.messages.append({"role": "assistant", "content": full_response})
elif authentication_status == False:
st.error('Username/password is incorrect')
elif authentication_status == None:
st.warning('Please enter your username and password')
- The error is that after one or two user inputs, the front end just stops displaying the assistant responses (on the cloud, locally all is working)
- I am using Python 3.10.4 and streamlit 1.28.2, streamlit-authenticator=0.2.3
Note: If I remove authentication, the app deploys to the Streamlit cloud without issue. I have logged the issue here as well.