From 3e31c1752e0e5bf90339b816f9895529d9368bbd Mon Sep 17 00:00:00 2001 From: Freddy Boulton Date: Wed, 1 Nov 2023 16:32:13 -0400 Subject: [PATCH] Add likeable to config for Chatbot (#6231) * Add likeable to config * add changeset * Add test --------- Co-authored-by: gradio-pr-bot --- .changeset/major-bushes-ring.md | 5 +++++ gradio/components/chatbot.py | 4 +++- test/test_components.py | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .changeset/major-bushes-ring.md diff --git a/.changeset/major-bushes-ring.md b/.changeset/major-bushes-ring.md new file mode 100644 index 0000000000..71cceb674d --- /dev/null +++ b/.changeset/major-bushes-ring.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Add likeable to config for Chatbot diff --git a/gradio/components/chatbot.py b/gradio/components/chatbot.py index 88e4d1245c..dccb6b4f34 100644 --- a/gradio/components/chatbot.py +++ b/gradio/components/chatbot.py @@ -66,6 +66,7 @@ class Chatbot(Component): render_markdown: bool = True, bubble_full_width: bool = True, line_breaks: bool = True, + likeable: bool = False, layout: Literal["panel", "bubble"] | None = None, ): """ @@ -91,9 +92,10 @@ class Chatbot(Component): render_markdown: If False, will disable Markdown rendering for chatbot messages. bubble_full_width: If False, the chat bubble will fit to the content of the message. If True (default), the chat bubble will be the full width of the component. line_breaks: If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies if `render_markdown` is True. + likeable: Whether the chat messages display a like or dislike button. Set automatically by the .like method but has to be present in the signature for it to show up in the config. layout: If "panel", will display the chatbot in a llm style layout. If "bubble", will display the chatbot with message bubbles, with the user and bot messages on alterating sides. Will default to "bubble". """ - self.likeable = False + self.likeable = likeable self.height = height self.rtl = rtl if latex_delimiters is None: diff --git a/test/test_components.py b/test/test_components.py index 026b85e787..9f20b33014 100644 --- a/test/test_components.py +++ b/test/test_components.py @@ -1895,6 +1895,23 @@ class TestJSON: "_selectable": False, } + def test_chatbot_selectable_in_config(self): + with gr.Blocks() as demo: + cb = gr.Chatbot(label="Chatbot") + cb.like(lambda: print("foo")) + gr.Chatbot(label="Chatbot2") + + assertion_count = 0 + for component in demo.config["components"]: + if component["props"]["label"] == "Chatbot": + assertion_count += 1 + assert component["props"]["likeable"] + elif component["props"]["label"] == "Chatbot2": + assertion_count += 1 + assert not component["props"]["likeable"] + + assert assertion_count == 2 + @pytest.mark.asyncio async def test_in_interface(self): """