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

Ensure undo/try shows for final bot message in gr.Chatbot #9600

Merged
merged 12 commits into from
Oct 9, 2024
6 changes: 6 additions & 0 deletions .changeset/large-impalas-take.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/chatbot": patch
"gradio": patch
---

fix:Ensure undo/try shows for final bot message in gr.Chatbot
8 changes: 4 additions & 4 deletions js/chatbot/shared/ButtonPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import { IconButtonWrapper, IconButton } from "@gradio/atoms";

export let likeable: boolean;
export let _retryable: boolean;
export let _undoable: boolean;
export let show_retry: boolean;
export let show_undo: boolean;
export let show_copy_button: boolean;
export let show: boolean;
export let message: NormalisedMessage | NormalisedMessage[];
Expand Down Expand Up @@ -65,14 +65,14 @@
<IconButton Icon={DownloadIcon} />
</DownloadLink>
{/if}
{#if _retryable}
{#if show_retry}
<IconButton
Icon={Retry}
on:click={() => handle_action("retry")}
disabled={disable}
/>
{/if}
{#if _undoable}
{#if show_undo}
<IconButton
Icon={Undo}
on:click={() => handle_action("undo")}
Expand Down
10 changes: 3 additions & 7 deletions js/chatbot/shared/ChatBot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,6 @@
>
</div>
{/if}
{@const show_like =
role === "user" ? likeable && like_user_message : likeable}
{@const show_retry = _retryable && is_last_bot_message(messages, value)}
{@const show_undo = _undoable && is_last_bot_message(messages, value)}
<Message
{messages}
{opposite_avatar_img}
Expand All @@ -320,9 +316,9 @@
{_components}
{generating}
{msg_format}
{show_like}
{show_retry}
{show_undo}
show_like={role === "user" ? likeable && like_user_message : likeable}
show_retry={_retryable && is_last_bot_message(messages, value)}
show_undo={_undoable && is_last_bot_message(messages, value)}
{show_copy_button}
handle_action={(selected) => handle_like(i, messages[0], selected)}
{scroll}
Expand Down
45 changes: 28 additions & 17 deletions js/chatbot/shared/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,32 @@
return `a component of type ${message.content.component ?? "unknown"}`;
}

function get_button_panel_props(): any {
return {
show: show_like || show_retry || show_undo || show_copy_button,
handle_action,
likeable: show_like,
_retryable: show_retry,
_undoable: show_undo,
disable: generating,
show_copy_button,
message: msg_format === "tuples" ? messages[0] : messages,
position: role === "user" ? "right" : "left",
avatar: avatar_img,
layout
};
}
type ButtonPanelProps = {
show: boolean;
handle_action: (selected: string | null) => void;
likeable: boolean;
show_retry: boolean;
show_undo: boolean;
disable: boolean;
show_copy_button: boolean;
message: NormalisedMessage[] | NormalisedMessage;
position: "left" | "right";
};

let button_panel_props: ButtonPanelProps;
$: button_panel_props = {
show: show_like || show_retry || show_undo || show_copy_button,
handle_action,
likeable: show_like,
show_retry,
show_undo,
disable: generating,
show_copy_button,
message: msg_format === "tuples" ? messages[0] : messages,
position: role === "user" ? "right" : "left",
avatar: avatar_img,
layout
};
</script>

<div
Expand Down Expand Up @@ -194,14 +205,14 @@
</div>

{#if layout === "panel"}
<ButtonPanel {...get_button_panel_props()} />
<ButtonPanel {...button_panel_props} />
{/if}
{/each}
</div>
</div>

{#if layout === "bubble"}
<ButtonPanel {...get_button_panel_props()} />
<ButtonPanel {...button_panel_props} />
{/if}

<style>
Expand Down
Loading