Has anyone had success in implementing forms into a streamlit chat? I am using an LLM to return the parameters, then creating a form for the user to fill out. I have successfully saved the form to session state and can regenerate the form on refresh, but the text_inputs are not being recorded. I have tried saving the names and values (in a dict) to session state and locally. Let me know, thanks.
def build_form(message):
body = message["body"]
params = message["content"]
with st.chat_message("assistant"):
with st.form(key="form"):
for name, value in params.items():
params[name] = st.text_input(label=name, value=value, key=name)
st.form_submit_button("Submit", on_click=save_form, args=[params, body])
def save_form(params, body):
st.session_state.all_messages.append(
{
"role": "assistant",
"content": params,
"type": "form",
"request_body": body,
}
)