Wait for radio button output in chatbot

iam building a chatbot in which when user asks the question and bot is not able to find intent it asks follow up question.
for this purpose i the questions are generated by llm and displayed on radio button
if intent.strip() == ‘Broad’: # Check if the intent is ‘Broad’
follow = followup(prompt, store, followup_que_template)
# Split questions and clean them up
ques = [que.strip() + ‘?’ for que in follow.split(‘?’) if que.strip()]

    with st.spinner("Wait for it ^_^"):
        # Display radio buttons for question selection
        genre = st.radio('Please select a specific query:', ques, index=None)

as i want like the control should wait in there only till radio selection is done by user then move further.
like the specific query’s answer will be answered by chatbot.
PLEASE ANYONE CAN HELP ME WITH THIS??

FOR REFERENCE HERE IS THE CODE:

#code starts here →

if prompt:
    with st.chat_message('user'):
    st.markdown(prompt)
prompt=prompt.lower()
print(prompt)
st.session_state.messages.append({"role":"user", "content": prompt})
intent=query_llama(intent_template.format(user_query=prompt))
print(intent)

if intent.strip() == 'Broad':  # Check if the intent is 'Broad'
    follow = followup(prompt, store, followup_que_template)
    # Split questions and clean them up
    ques = [que.strip() + '?' for que in follow.split('?') if que.strip()]
    
    with st.spinner("Wait for it ^_^"):
        # Display radio buttons for question selection
        genre = st.radio('Please select a specific query:', ques, index=None)
        # time.sleep(5)
    if genre and not st.session_state.genre_selected:
        st.session_state.genre_selected = True
        st.session_state.response=False
    print(genre)

    # Only proceed once an option is selected
    if st.session_state.genre_selected:
        with st.spinner("Wait for it ^_^"):
            response = f"{query_with_template_and_sources(genre, store)}"
            st.session_state.genre_selected=False
            st.session_state.response=True
else:
    # Directly generate the response if the intent is not broad
    with st.spinner("Wait for it ^_^"):
        response = f"{query_with_template_and_sources(prompt, store)}"
        st.session_state.response=True
    
if st.session_state.response:
    # display assitant response
    with st.chat_message("assistant"):
        st.markdown(response)
    st.session_state.iterr +=1
    summarised_prompt=summary_template.format(human_prompt=prompt, llm_response=response)
    st.session_state.summarised_history.append(query_llama(summarised_prompt))
    if st.session_state.iterr>2:
        temp=''
        for item in st.session_state.summarised_history:
            temp = temp+ item
        st.session_state.summarised_history =[query_llama(summary.format(content=temp)).replace('\n', '')]
        st.session_state.iterr=1

    # if 'mail me:' in prompt:
    #     mail.sendEmail(st.session_state.email, st.session_state.user_name, response)
    
    # add assitant response to chat history
    st.session_state.messages.append({"role":"assistant", "content":response})

Could you format your code properly?

1 Like

yeah i have formated it now can you please review it now?

i want to implement the some similar to javascript’s async await like the control should wait till the user responds to radio input

Hello ferdy can you please look at query? If it can be solved

You can’t do that. Instead, you can decide what to do or not to do depending of the control’s value.

prompt is undefined in the first line.