-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset flagged values when switching conversations in chat history #10292
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-pypi-previews.s3.amazonaws.com/1485016253b16a502cd334c01d3e6aee37ba0aa2/gradio-5.9.1-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@1485016253b16a502cd334c01d3e6aee37ba0aa2#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-npm-previews.s3.amazonaws.com/1485016253b16a502cd334c01d3e6aee37ba0aa2/gradio-client-1.8.0.tgz Use Lite from this PR <script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/1485016253b16a502cd334c01d3e6aee37ba0aa2/dist/lite.js""></script> |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
gradio/chat_interface.py
Outdated
while len(feedback_value) <= assistant_index: | ||
feedback_value.append(None) | ||
feedback_value[assistant_index] = value | ||
feedback_values[str(conversation_id)] = feedback_value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orjson
requires dictionaries to have str
keys, otherwise serialization fails and the gradio app crashes.
@@ -249,7 +249,10 @@ def __init__( | |||
|
|||
with self: | |||
self.saved_conversations = BrowserState( | |||
[], storage_key="_saved_conversations" | |||
[], storage_key=f"_saved_conversations_{self._id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds a self._id
in case your Gradio app has multiple gr.ChatInterface
-s
[], storage_key=f"_saved_conversations_{self._id}" | |
[], storage_key=f"_saved_conversations_{self._id}" |
inputs=[self.saved_conversations], | ||
outputs=[self.chat_history_dataset], | ||
show_api=False, | ||
queue=False, | ||
) | ||
def load_chat_history(conversations): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to avoid using decorator syntax for consistency with the rest of the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and fixes the flagging issues.
@aliabid94 thoughts on changing to a primary button? like this: |
Concern about storing flagged info in two different places (in csv, and in browser state) is that they may diverge. For example, a user may delete the csv to clear the flagging history, but it will still show up in the browser. |
Synced with @aliabid94 about this:
and decided to change this approach to reset the flagging values instead of preserving them in browser state. Simplifies the PR considerably. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @dawoodkhan82 @aliabid94 for the reviews! |
When both flagging (#10272) and chat history (#10191) are enabled, flagged messages are shared between conversations. E.g. if you flag the first message in one conversation, the first message appears to be flagged in all conversations.
This PR fixes that -- now the flagged values are
saved as part of the chat history for each conversation separatelyreset. This PR also makes a few small tweaks to improve the UI/UX saving history and flagging:gr.Chatbot
#10286For an example with only
gr.Chatbot
, try something like this:Or test the whole experience of switching between conversations using the
demo/chatinterface_streaming_echo/run.py
demo.