Skip to content
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

Group chatbot messages by default #10169

Merged
merged 39 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1910029
handle pasted text as file
hannahblair Dec 5, 2024
25c17bd
test
hannahblair Dec 5, 2024
29a91ee
add changeset
gradio-pr-bot Dec 5, 2024
b776610
remove unneeded test
hannahblair Dec 5, 2024
589c9ef
Merge branch 'pasted-text-chatbot' of github.com:gradio-app/gradio in…
hannahblair Dec 5, 2024
7cac5ef
update file UI
hannahblair Dec 5, 2024
da138de
Merge branch 'main' into uploaded-file-UI
hannahblair Dec 5, 2024
282d753
add changeset
gradio-pr-bot Dec 5, 2024
0003e10
Revert "handle pasted text as file"
hannahblair Dec 9, 2024
73eed0d
add changeset
gradio-pr-bot Dec 9, 2024
30d999a
Revert "test"
hannahblair Dec 9, 2024
b0f3b15
Merge branch 'uploaded-file-UI' of github.com:gradio-app/gradio into …
hannahblair Dec 9, 2024
0ce8e7b
Merge branch 'main' into uploaded-file-UI
hannahblair Dec 9, 2024
e66bbde
story
hannahblair Dec 9, 2024
c92355f
Merge branch 'uploaded-file-UI' of github.com:gradio-app/gradio into …
hannahblair Dec 9, 2024
9ed057e
remove border
hannahblair Dec 9, 2024
da5e6cb
Revert "add changeset"
hannahblair Dec 9, 2024
fca34e2
Merge branch 'main' into uploaded-file-UI
hannahblair Dec 9, 2024
19f9e37
add changeset
gradio-pr-bot Dec 9, 2024
c5261d9
Merge branch 'uploaded-file-UI' into group-chatbot-messages-default
freddyaboulton Dec 10, 2024
4e7657c
add code
freddyaboulton Dec 10, 2024
d9b65e5
Code
freddyaboulton Dec 10, 2024
49956b2
merge
freddyaboulton Dec 10, 2024
e97cd8f
add code
freddyaboulton Dec 10, 2024
a3e9da2
add changeset
gradio-pr-bot Dec 10, 2024
bdea3ce
Update solid-hands-nail.md
freddyaboulton Dec 10, 2024
c8f533d
code
freddyaboulton Dec 10, 2024
1cea649
add metadata typecheck
hannahblair Dec 10, 2024
ae620ec
trigger ci
freddyaboulton Dec 10, 2024
f1ea8f8
remove thought css
freddyaboulton Dec 10, 2024
54a2956
Revert "remove thought css"
freddyaboulton Dec 10, 2024
ee9665c
Merge branch 'main' into group-chatbot-messages-default
freddyaboulton Dec 12, 2024
e407ad2
fix tuples - add borders
freddyaboulton Dec 13, 2024
898452b
lint
freddyaboulton Dec 13, 2024
96855e8
Fix typecheck
freddyaboulton Dec 13, 2024
073c9b0
css tweak
hannahblair Dec 13, 2024
f71dd50
add code
freddyaboulton Dec 13, 2024
6ab8f91
merge main
freddyaboulton Dec 13, 2024
c5e4d46
fix parameter name
freddyaboulton Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/solid-hands-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/chatbot": minor
"gradio": minor
---

feat:By default, consecutive messages are displayed in the same bubble. This is controlled by the new `display_consecutive_in_same_bubble` param of Chatbot.
3 changes: 3 additions & 0 deletions gradio/components/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def __init__(
examples: list[ExampleMessage] | None = None,
show_copy_all_button=False,
allow_file_downloads=True,
group_consecutive_messages: bool = True,
):
"""
Parameters:
Expand Down Expand Up @@ -235,6 +236,7 @@ def __init__(
examples: A list of example messages to display in the chatbot before any user/assistant messages are shown. Each example should be a dictionary with an optional "text" key representing the message that should be populated in the Chatbot when clicked, an optional "files" key, whose value should be a list of files to populate in the Chatbot, an optional "icon" key, whose value should be a filepath or URL to an image to display in the example box, and an optional "display_text" key, whose value should be the text to display in the example box. If "display_text" is not provided, the value of "text" will be displayed.
show_copy_all_button: If True, will show a copy all button that copies all chatbot messages to the clipboard.
allow_file_downloads: If True, will show a download button for chatbot messages that contain media. Defaults to True.
group_consecutive_messages: If True, will display consecutive messages from the same role in the same bubble. If False, will display each message in a separate bubble. Defaults to True.
"""
if type is None:
warnings.warn(
Expand All @@ -259,6 +261,7 @@ def __init__(
self.max_height = max_height
self.min_height = min_height
self.rtl = rtl
self.group_consecutive_messages = group_consecutive_messages
if latex_delimiters is None:
latex_delimiters = [{"left": "$$", "right": "$$", "display": True}]
self.latex_delimiters = latex_delimiters
Expand Down
18 changes: 15 additions & 3 deletions js/atoms/src/IconButtonWrapper.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<script>
export let top_panel = true;
export let display_top_corner = false;
</script>

<div class={`icon-button-wrapper ${top_panel ? "top-panel" : ""}`}>
<div
class={`icon-button-wrapper ${top_panel ? "top-panel" : ""} ${display_top_corner ? "display-top-corner" : "hide-top-corner"}`}
>
<slot></slot>
</div>

Expand All @@ -16,11 +19,20 @@
gap: var(--spacing-sm);
box-shadow: var(--shadow-drop);
border: 1px solid var(--border-color-primary);
background: var(--block-background-fill);
padding: var(--spacing-xxs);
}

.icon-button-wrapper.hide-top-corner {
border-top: none;
border-right: none;
border-radius: var(--block-label-right-radius);
background: var(--block-background-fill);
padding: var(--spacing-xxs);
}

.icon-button-wrapper.display-top-corner {
border-radius: var(--radius-sm) 0 0 var(--radius-sm);
top: var(--spacing-sm);
right: -1px;
}

.icon-button-wrapper:not(.top-panel) {
Expand Down
5 changes: 4 additions & 1 deletion js/audio/static/StaticAudio.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
export let waveform_options: WaveformOptions;
export let editable = true;
export let loop: boolean;
export let display_icon_button_wrapper_top_corner = false;
const dispatch = createEventDispatcher<{
change: FileData;
Expand All @@ -45,7 +46,9 @@
/>

{#if value !== null}
<IconButtonWrapper>
<IconButtonWrapper
display_top_corner={display_icon_button_wrapper_top_corner}
>
{#if show_download_button}
<DownloadLink
href={value.is_stream
Expand Down
64 changes: 64 additions & 0 deletions js/chatbot/Chatbot.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,38 @@ This document is a showcase of various Markdown capabilities.`,
}}
/>

<Story
name="Consecutive messages grouped in same bubble"
args={{
type: "messages",
display_consecutive_in_same_bubble: true,
value: [
{
role: "user",
content: "Show me the file."
},
{
role: "user",
content: "Second user message"
},
{
role: "assistant",
content: "Here is the file you requested"
},
{
role: "assistant",
content: {
file: {
path: "abc/qwerty.txt",
url: ""
},
alt_text: null
}
}
]
}}
/>

<Story
name="MultimodalChatbot with examples"
args={{
Expand Down Expand Up @@ -327,6 +359,38 @@ This document is a showcase of various Markdown capabilities.`,
}}
/>

<Story
name="Consecutive messages not grouped in same bubble"
args={{
type: "messages",
display_consecutive_in_same_bubble: false,
value: [
{
role: "user",
content: "Show me the file."
},
{
role: "user",
content: "Second user message"
},
{
role: "assistant",
content: "Here is the file you requested"
},
{
role: "assistant",
content: {
file: {
path: "abc/qwerty.txt",
url: ""
},
alt_text: null
}
}
]
}}
/>

<Story
name="Chatbot with examples (not multimodal)"
args={{
Expand Down
2 changes: 2 additions & 0 deletions js/chatbot/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
export let autoscroll = true;
export let _retryable = false;
export let _undoable = false;
export let group_consecutive_messages = true;
export let latex_delimiters: {
left: string;
right: string;
Expand Down Expand Up @@ -127,6 +128,7 @@
{show_copy_all_button}
value={_value}
{latex_delimiters}
display_consecutive_in_same_bubble={group_consecutive_messages}
{render_markdown}
{theme_mode}
pending_message={loading_status?.status === "pending"}
Expand Down
2 changes: 2 additions & 0 deletions js/chatbot/shared/ChatBot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
export let _fetch: typeof fetch;
export let load_component: Gradio["load_component"];
export let allow_file_downloads: boolean;
export let display_consecutive_in_same_bubble: boolean;

let _components: Record<string, ComponentType<SvelteComponent>> = {};

Expand Down Expand Up @@ -278,6 +279,7 @@
{@const opposite_avatar_img = avatar_images[role === "user" ? 0 : 1]}
<Message
{messages}
{display_consecutive_in_same_bubble}
{opposite_avatar_img}
{avatar_img}
{role}
Expand Down
5 changes: 5 additions & 0 deletions js/chatbot/shared/Component.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
export let upload;
export let _fetch;
export let allow_file_downloads: boolean;
export let display_icon_button_wrapper_top_corner = false;
</script>

{#if type === "gallery"}
<svelte:component
this={components[type]}
{value}
{display_icon_button_wrapper_top_corner}
show_label={false}
{i18n}
label=""
Expand Down Expand Up @@ -47,6 +49,7 @@
waveform_settings={{ autoplay: props.autoplay }}
waveform_options={{}}
show_download_button={allow_file_downloads}
{display_icon_button_wrapper_top_corner}
on:load
/>
{:else if type === "video"}
Expand All @@ -58,6 +61,7 @@
show_share_button={true}
{i18n}
{upload}
{display_icon_button_wrapper_top_corner}
show_download_button={allow_file_downloads}
on:load
>
Expand All @@ -70,6 +74,7 @@
show_label={false}
label="chatbot-image"
show_download_button={allow_file_downloads}
{display_icon_button_wrapper_top_corner}
on:load
{i18n}
/>
Expand Down
Loading
Loading