Skip to content

Commit

Permalink
Tweak Chatbot bubble_full_width behaviour (#10132)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahblair authored Dec 7, 2024
1 parent b7e4041 commit 6645518
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .changeset/little-bees-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@gradio/chatbot": minor
"@self/component-test": minor
"gradio": minor
---

feat:Tweak Chatbot `bubble_full_width` behaviour
11 changes: 8 additions & 3 deletions gradio/components/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def __init__(
avatar_images: tuple[str | Path | None, str | Path | None] | None = None,
sanitize_html: bool = True,
render_markdown: bool = True,
bubble_full_width: bool = True,
bubble_full_width=None,
line_breaks: bool = True,
layout: Literal["panel", "bubble"] | None = None,
placeholder: str | None = None,
Expand Down Expand Up @@ -225,7 +225,7 @@ def __init__(
avatar_images: Tuple of two avatar image paths or URLs for user and bot (in that order). Pass None for either the user or bot image to skip. Must be within the working directory of the Gradio app or an external URL.
sanitize_html: If False, will disable HTML sanitization for chatbot messages. This is not recommended, as it can lead to security vulnerabilities.
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.
bubble_full_width: Deprecated.
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.
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".
placeholder: a placeholder message to display in the chatbot when it is empty. Centered vertically and horizontally in the Chatbot. Supports Markdown and HTML. If None, no placeholder is displayed.
Expand Down Expand Up @@ -266,7 +266,12 @@ def __init__(
self.render_markdown = render_markdown
self.show_copy_button = show_copy_button
self.sanitize_html = sanitize_html
self.bubble_full_width = bubble_full_width
if bubble_full_width is not None:
warnings.warn(
"The 'bubble_full_width' parameter is deprecated and will be removed in a future version. This parameter no longer has any effect.",
DeprecationWarning,
)
self.bubble_full_width = None
self.line_breaks = line_breaks
self.layout = layout
self.show_copy_all_button = show_copy_all_button
Expand Down
11 changes: 1 addition & 10 deletions js/chatbot/Chatbot.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,10 @@
}}
/>

<Story
name="Chatbot with chat bubble full width disabled and copy button"
args={{
bubble_full_width: false,
show_copy_button: true
}}
/>

<Story
name="Chatbot with panel layout enabled and avatars"
args={{
show_copy_button: true,
layout: "panel",
avatar_images: [
{ url: "https://avatars.githubusercontent.com/u/100000?v=4" },
Expand All @@ -106,7 +99,6 @@
<Story
name="Chatbot with bubble layout enabled and avatars"
args={{
bubble_full_width: true,
layout: "bubble",
avatar_images: [
{ url: "https://avatars.githubusercontent.com/u/100000?v=4" },
Expand All @@ -118,7 +110,6 @@
<Story
name="Chatbot with percentage height"
args={{
bubble_full_width: false,
layout: "panel",
height: "50%"
}}
Expand Down
2 changes: 0 additions & 2 deletions js/chatbot/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
export let show_copy_button = true;
export let show_copy_all_button = false;
export let sanitize_html = true;
export let bubble_full_width = true;
export let layout: "bubble" | "panel" = "bubble";
export let type: "tuples" | "messages" = "tuples";
export let render_markdown = true;
Expand Down Expand Up @@ -149,7 +148,6 @@
on:copy={(e) => gradio.dispatch("copy", e.detail)}
{avatar_images}
{sanitize_html}
{bubble_full_width}
{line_breaks}
{autoscroll}
{layout}
Expand Down
2 changes: 0 additions & 2 deletions js/chatbot/shared/ChatBot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
export let show_copy_button = false;
export let avatar_images: [FileData | null, FileData | null] = [null, null];
export let sanitize_html = true;
export let bubble_full_width = true;
export let render_markdown = true;
export let line_breaks = true;
export let autoscroll = true;
Expand Down Expand Up @@ -291,7 +290,6 @@
{upload}
{selectable}
{sanitize_html}
{bubble_full_width}
{render_markdown}
{rtl}
{i}
Expand Down
10 changes: 0 additions & 10 deletions js/chatbot/shared/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
export let role = "user";
export let messages: NormalisedMessage[] = [];
export let layout: "bubble" | "panel";
export let bubble_full_width: boolean;
export let render_markdown: boolean;
export let latex_delimiters: {
left: string;
Expand Down Expand Up @@ -121,7 +120,6 @@
class="message {role} {is_component_message(message)
? message?.content.component
: ''}"
class:message-fit={layout === "bubble" && !bubble_full_width}
class:panel-full-width={true}
class:message-markdown-disabled={!render_markdown}
class:component={message.type === "component"}
Expand Down Expand Up @@ -303,10 +301,6 @@
border-radius: var(--radius-md);
}
.message-fit {
width: fit-content !important;
}
.panel-full-width {
width: 100%;
}
Expand Down Expand Up @@ -382,10 +376,6 @@
margin-left: calc(var(--spacing-xxl) + 35px + var(--spacing-xxl));
}
.bubble .message-fit {
width: fit-content !important;
}
/* panel mode styles */
.panel {
margin: 0;
Expand Down
2 changes: 1 addition & 1 deletion js/component-test/src/lib/component_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export default [
avatar_images: [null, null],
sanitize_html: true,
render_markdown: true,
bubble_full_width: true,
bubble_full_width: null,
line_breaks: true,
show_copy_all_button: false,
name: "chatbot",
Expand Down
2 changes: 1 addition & 1 deletion test/components/test_chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_component_functions(self):
"avatar_images": [None, None],
"sanitize_html": True,
"render_markdown": True,
"bubble_full_width": True,
"bubble_full_width": None,
"line_breaks": True,
"layout": None,
"show_copy_all_button": False,
Expand Down

0 comments on commit 6645518

Please sign in to comment.