Open bpkapkar opened 8 months ago
The component returns None
if the app is rerun without interacting with the component. I tried your code on my side and everything seems to work correctly to me?
Thanks @jeffkayne for looking into it and answering it. In addition to it I am able to get return multiple value when user interacts with thumbs. one another challenge I am finding is , we are unable to return 2 values from the function given in below function and give key value error or even we reply user_response that's look like complete dictionary that doesn't work like key value function and gets key error
def _submit_feedback(user_response, emoji=None): st.toast(f"Feedback submitted: {user_response}", icon=emoji) print(user_response) print(user_response["text"]) return user_response["score"], user_response["text"]
One more query how to identify the which thumbs has been clicked from series of thumbs that is available chat app so we can record the corresponding message to that thumbs reaction. How do we use feedback_key in this .
the on_submit=
funcion shouldn't return anything. It is a handler function that can do some action (e.g. save the response to a db) after submitting. To get the user_response, you should simply use the return variable of the component. In your example, that is the test
variable
Thanks @jeffkayne for looking into my query, to clarify more detail what I am trying to achieve. I am trying to record multiple data points example , score and text. Below is the example when I am passing the function
def _submit_feedback(user_response, emoji=None): st.toast(f"Feedback submitted: {user_response}", icon=emoji)
I am able to get the response π
this works fine.
def _submit_feedback(user_response, emoji=None): st.toast(f"Feedback submitted: {user_response}", icon=emoji) return user_response["score"], user_response["text"] and modifying the function
reply1,reply2=streamlit_feedback( feedback_type="thumbs", optional_text_label="Please provide extra information", on_submit=_submit_feedback, key=feedback_key, )
We get the error
reply1,reply2=streamlit_feedback(
TypeError: cannot unpack non-iterable NoneType object
def _submit_feedback(user_response, emoji=None): st.toast(f"Feedback submitted: {user_response}", icon=emoji) return user_response
reply1=streamlit_feedback( feedback_type="thumbs", optional_text_label="Please provide extra information", on_submit=_submit_feedback, key=feedback_key, ) print(reply1["score"])
We get the error print(reply1["score"]) TypeError: 'NoneType' object is not subscriptable
As I was looking to record the multiple data points I was facing this challenge as well . I found there might some code changes required in base library or I need to do correct things
To store multiple data points, you need to reset your feedback component by using a dynamic key.
Here is some code that stores multiple feedback results in a session state variable:
import streamlit as st
from streamlit_feedback import streamlit_feedback
def handle_feedback(user_response):
st.toast("βοΈ Feedback received!")
if "feedback" not in st.session_state:
st.session_state.feedback = []
if "feedback_key" not in st.session_state:
st.session_state.feedback_key = 0
if st.button("Refresh feedback component"):
st.session_state.feedback_key += 1 # overwrite feedback component
result = streamlit_feedback(
feedback_type="thumbs",
align="flex-start",
on_submit=handle_feedback,
key=f"feedback_{st.session_state.feedback_key}",
)
if result:
st.session_state.feedback.append(result)
# view session state
st.session_state.feedback
I have made changes to the code, but it seems that there is an issue when using it with st.chat_input. The example code works correctly without it, but when integrated with st.chat_input, it returns None as the value. I have reviewed the modified code to identify any mistakes, but the problem persists. As I need to store user input in a variable and check actions accordingly. below is the sample code import streamlit as st from streamlit_feedback import streamlit_feedback
def _submit_feedback(user_response, emoji=None): st.toast(f"Feedback submitted: {user_response}", icon=emoji) return user_response.update({"some metadata": 123})
def chatbot_thumbs_app(streamlit_feedback, debug=False): st.title("π¬ Chatbot") openai_api_key="sadd" if "messages" not in st.session_state: st.session_state["messages"] = [ {"role": "assistant", "content": "How can I help you?"} ]
chatbot_thumbs_app(streamlit_feedback)