Help needed for streamlit feedback

I implemented streamlit feedback in my code . But it’s doesn’t show immediately after generating a response. I need to ask a question/ click any button to trigger the feedback buttons. how to resolve it? below is the code snippet:

async def handle_chat():
if st.session_state.sample_questions:
# Handle the display of suggested questions
handle_suggested_questions()

# Prompt the user for a question
prompt = st.chat_input("Your question")
if prompt and prompt.strip():
    st.session_state.messages.append({"role": "user", "content": prompt})
elif prompt is not None:  # Check if input was provided but is empty
    st.warning("Please enter a valid question.")

# Display previous messages with feedback
for n, message in enumerate(st.session_state.messages, start=1):
    with st.chat_message(message["role"]):
        st.write(message["content"])

    if message["role"] == "assistant":
        # feedback_key = f"feedback_{n}"
        # feedback_key = f"feedback_{int(time.time()*1000*10)}"
        feedback_key = f"feedback_{uuid.uuid4().hex}"

        if feedback_key not in st.session_state:
            st.session_state[feedback_key] = None

        feedback = streamlit_feedback(
            feedback_type="thumbs",
            align="flex-start",
            on_submit=submit_feedback,
            key=feedback_key,
        )

        if feedback:
            process_feedback(feedback, feedback_key)

# Generate a response if the last message is from the user
if st.session_state.messages and st.session_state.messages[-1]["role"] == "user":
    last_message = st.session_state.messages[-1]
    user_input = last_message["content"]
    await generate_response(user_input)

def process_feedback(feedback, feedback_key):
if feedback[“score”] == “:+1:”:
feedback_type = “positive”
elif feedback[“score”] == “:-1:”:
feedback_type = “negative”

question = feedback["question"]
sql = feedback["sql"].strip()
response = str(feedback["response"].strip())

I make a custom feedback that you might get interested.

Hi @Sarah1 , were you able to find a fix for this?

In my case am passing one more additional argument that is on_submit =_submit_feedback

Function of _submit_feedback
def _submit_feedback(user_response, emoji=None):
st.toast(f"Feedback submitted: {user_response}", icon=emoji)
return user_response.update({“some metadata”: 123})

I am able to get the dictionary object of the feedback response, but I couldn’t access the ‘score’ key with following code.
if isinstance(st.session_state.returned,dict):
print(“Recieved the dict object”)
if st.session_state.returned.get(‘score’) == ‘:+1:’:
message[“feedback”] = ‘:+1:
logging.info(f"Got POSITIVE feedback for question")
elif st.session_state.returned.get(‘score’) == ‘:-1:’:
message[“feedback”] = ‘:-1:
logging.info(f"Got NEGATIVE feedback for question")

I tired with st.session_state.returned[“score”], still didn’t resolved.

package : streamlit-feedback
version :0.1.3

If anyone could please assist me with this issue, I would be very grateful.

Thank you in advance!