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.