def submit():
record_timing() # Record time before submitting message
st.session_state.something = st.session_state.widget
st.session_state.widget = ''
if "messages" not in st.session_state:
st.session_state.messages = [{"role": "assistant", "content": "How may I help you today?"}]
if user_prompt := st.text_input("Your message here", on_change=submit, key="text_input"): # Assign unique key
st.session_state.messages.append({"role": "user", "content": user_prompt})
with st.chat_message("user"):
st.write(user_prompt)
if st.session_state.messages[-1]["role"] != "assistant":
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
response = model(user_prompt, max_length, temp)
placeholder = st.empty()
full_response = ''
for item in response:
full_response += item
placeholder.markdown(full_response)
placeholder.markdown(full_response)
message = {"role": "assistant", "content": full_response}
st.session_state.messages.append(message)
here even after user submits the query, the text_input is not being cleared out
as u can see below,