Pass object to callback function

Hi,

I’m new to Streamlit and I have a question about using callback functions.

I want to create a prompt that calls a function “process_message” when on-submit
This codes works

def process_message():
st.write(“test”)

prompt = st.chat_input(" Ask your question here: ",on_submit=process_message)

As a next step, I want to access the text entered in my prompt within my callback function.
How can I do that?

Regards

In three easy steps:

  1. Add a key to the chat input.
prompt = st.chat_input("Ask your question here: ", on_submit=process_message, key="prompt")
  1. Use session state and the key to access the value.
def process_message():
    st.write(st.session_state.prompt)
  1. Profit!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.