Add likeable to config for Chatbot (#6231)

* Add likeable to config

* add changeset

* Add test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Freddy Boulton 2023-11-01 16:32:13 -04:00 committed by GitHub
parent 874005938d
commit 3e31c1752e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Add likeable to config for Chatbot

View File

@ -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:

View File

@ -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):
"""