Like/dislike buttons for feedback in st.chat_input

Summary

I want to add a like :+1: and :-1: option for each answer in a chatbot (like ChatGPT) to collect feedback and use that for fine tuning. I need ideas for how I can do this?

Expected behavior:

When user clicks :+1:, it should highlight :+1: and vice versa, just like radio buttons! I should also be able to receive input in variables so that I can use that to store feedback to a CSV.

What I have tried:

I tried using button group component - New Component: Button Group
As soon as it reaches the code block for st_btn_group, the app reruns MULTIPLE times, that makes it very glitchy. Is there any possible solution for this?

Here I am attaching the code I’m using -

buttons = [
  {"label": "πŸ‘",
   "value": "like",
   "style": {"border-radius": "22px", "padding": "1px"}
   },
  {"label": "πŸ‘Ž",
   "value": "dislike",
   "style": {"border-radius": "22px", "padding": "1px"}
   }
]

col = st.columns([92, 8])
with col[1]:
  returned = st_btn_group(buttons=buttons, key=message["query_id"], mode='radio',
                          return_value=True)

Here if you try to store β€œreturned” into a list, it will return β€œlike” or β€œdislike” multiple times for 1 question.

So this is a no-go.

I’m looking for any creative ideas! Thanks in advance! :slight_smile:

1 Like

Hello @Manas_Swami! :wave:

Thank you for your question!

I would recommend using the ace Feedback component from Trubrics for this!

Trubrics Feedback Blog Post
Trubrics Demo App

I have some experience using it myself, so feel free to reach out if you have any questions. I’ll do my best to assist you! :slightly_smiling_face:

Best,
Charly

Hi, thanks for the reply! Actually, I don’t want to use a third-party app for this. Instead, I am saving everything to a seaprate database including user information and feedback.
Although, I stumbled upon this - GitHub - trubrics/streamlit-feedback: Collect user feedback from within your Streamlit app

Here the issue is

user_input = st.chat_input("Type your question here or type an SQL query to run...")
if user_input:
    logging.info(f"Received new user input - {user_input}")

# Processing the user input here ---
# After processing -
with st.chat_message("assistant"):
    st.markdown("answer from LLM")
# Feedback code
    feedback = streamlit_feedback(feedback_type="thumbs", key=query_id_key)
    print(feedback)

Sorry this is a very small part of the code because the code is v large. Now here if I click on either like or dislike, the app reruns without storing the feedback and goes to my history display loop. How do I store this feedback? Any ideas?

if β€œbtn_value” not in st.session_state:
st.session_state.btn_value = None

Try to define st.session_state for button group and can be used elsewhere in the app without triggering unnecessary reruns. Let me know if it works.