Skip to content

Commit

Permalink
Add likeable to config for Chatbot (#6231)
Browse files Browse the repository at this point in the history
* Add likeable to config

* add changeset

* Add test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
freddyaboulton and gradio-pr-bot committed Nov 1, 2023
1 parent 8740059 commit 3e31c17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/major-bushes-ring.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Add likeable to config for Chatbot
4 changes: 3 additions & 1 deletion gradio/components/chatbot.py
Expand Up @@ -66,6 +66,7 @@ def __init__(
render_markdown: bool = True,
bubble_full_width: bool = True,
line_breaks: bool = True,
likeable: bool = False,
layout: Literal["panel", "bubble"] | None = None,
):
"""
Expand All @@ -91,9 +92,10 @@ def __init__(
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:
Expand Down
17 changes: 17 additions & 0 deletions test/test_components.py
Expand Up @@ -1895,6 +1895,23 @@ def test_component_functions(self):
"_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):
"""
Expand Down

0 comments on commit 3e31c17

Please sign in to comment.