2023-10-31 12:46:02 +08:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
export { default as BaseChatBot } from "./shared/ChatBot.svelte";
|
|
|
|
</script>
|
|
|
|
|
2022-03-08 21:35:42 +08:00
|
|
|
<script lang="ts">
|
2023-09-02 07:20:55 +08:00
|
|
|
import type { Gradio, SelectData, LikeData } from "@gradio/utils";
|
2023-08-24 04:48:10 +08:00
|
|
|
|
2023-10-31 12:46:02 +08:00
|
|
|
import ChatBot from "./shared/ChatBot.svelte";
|
2022-06-02 01:02:18 +08:00
|
|
|
import { Block, BlockLabel } from "@gradio/atoms";
|
2023-07-14 00:41:47 +08:00
|
|
|
import type { LoadingStatus } from "@gradio/statustracker";
|
2022-06-02 01:02:18 +08:00
|
|
|
import { Chat } from "@gradio/icons";
|
2024-02-08 06:39:33 +08:00
|
|
|
import type { FileData } from "@gradio/client";
|
2023-07-14 00:41:47 +08:00
|
|
|
import { StatusTracker } from "@gradio/statustracker";
|
2024-07-10 19:08:06 +08:00
|
|
|
import type {
|
|
|
|
Message,
|
|
|
|
TupleFormat,
|
|
|
|
MessageRole,
|
|
|
|
NormalisedMessage
|
|
|
|
} from "./types";
|
2022-03-29 21:10:35 +08:00
|
|
|
|
2024-07-10 19:08:06 +08:00
|
|
|
import { normalise_tuples, normalise_messages } from "./shared/utils";
|
2024-06-14 22:43:35 +08:00
|
|
|
|
2023-07-14 00:41:47 +08:00
|
|
|
export let elem_id = "";
|
|
|
|
export let elem_classes: string[] = [];
|
|
|
|
export let visible = true;
|
2024-07-10 19:08:06 +08:00
|
|
|
export let value: TupleFormat | Message[] = [];
|
2023-06-22 03:34:12 +08:00
|
|
|
export let scale: number | null = null;
|
2023-06-08 09:35:31 +08:00
|
|
|
export let min_width: number | undefined = undefined;
|
2022-06-02 01:02:18 +08:00
|
|
|
export let label: string;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let show_label = true;
|
2023-03-04 10:17:48 +08:00
|
|
|
export let root: string;
|
2023-10-31 12:46:02 +08:00
|
|
|
export let _selectable = false;
|
2023-09-02 07:20:55 +08:00
|
|
|
export let likeable = false;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let show_share_button = false;
|
2023-07-18 00:53:23 +08:00
|
|
|
export let rtl = false;
|
2024-06-25 05:41:06 +08:00
|
|
|
export let show_copy_button = true;
|
2023-08-29 12:26:29 +08:00
|
|
|
export let sanitize_html = true;
|
2023-08-29 08:48:52 +08:00
|
|
|
export let bubble_full_width = true;
|
2023-10-03 01:29:20 +08:00
|
|
|
export let layout: "bubble" | "panel" = "bubble";
|
2024-07-12 19:53:28 +08:00
|
|
|
export let type: "tuples" | "messages" = "tuples";
|
2023-09-23 02:53:09 +08:00
|
|
|
export let render_markdown = true;
|
2023-10-03 11:44:58 +08:00
|
|
|
export let line_breaks = true;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let latex_delimiters: {
|
2023-06-15 21:27:18 +08:00
|
|
|
left: string;
|
|
|
|
right: string;
|
|
|
|
display: boolean;
|
2023-08-04 06:01:18 +08:00
|
|
|
}[];
|
2023-08-24 04:48:10 +08:00
|
|
|
export let gradio: Gradio<{
|
|
|
|
change: typeof value;
|
|
|
|
select: SelectData;
|
|
|
|
share: ShareData;
|
|
|
|
error: string;
|
2023-09-02 07:20:55 +08:00
|
|
|
like: LikeData;
|
2024-04-20 03:38:53 +08:00
|
|
|
clear_status: LoadingStatus;
|
2023-08-24 04:48:10 +08:00
|
|
|
}>;
|
2024-02-27 05:01:00 +08:00
|
|
|
export let avatar_images: [FileData | null, FileData | null] = [null, null];
|
2023-08-04 06:01:18 +08:00
|
|
|
|
2024-07-10 19:08:06 +08:00
|
|
|
let _value: NormalisedMessage[] | null = [];
|
2023-10-31 12:46:02 +08:00
|
|
|
|
2024-07-10 19:08:06 +08:00
|
|
|
$: _value =
|
2024-07-12 19:53:28 +08:00
|
|
|
type === "tuples"
|
2024-07-10 19:08:06 +08:00
|
|
|
? normalise_tuples(value as TupleFormat, root)
|
|
|
|
: normalise_messages(value as Message[], root);
|
2023-08-22 05:15:59 +08:00
|
|
|
|
2023-03-13 22:21:03 +08:00
|
|
|
export let loading_status: LoadingStatus | undefined = undefined;
|
2023-07-14 00:41:47 +08:00
|
|
|
export let height = 400;
|
2024-03-28 03:13:17 +08:00
|
|
|
export let placeholder: string | null = null;
|
2024-06-14 22:43:35 +08:00
|
|
|
export let theme_mode: "system" | "light" | "dark";
|
2022-03-08 21:35:42 +08:00
|
|
|
</script>
|
|
|
|
|
2023-06-08 09:35:31 +08:00
|
|
|
<Block
|
|
|
|
{elem_id}
|
|
|
|
{elem_classes}
|
|
|
|
{visible}
|
|
|
|
padding={false}
|
|
|
|
{scale}
|
|
|
|
{min_width}
|
|
|
|
{height}
|
|
|
|
allow_overflow={false}
|
|
|
|
>
|
2023-06-06 09:11:53 +08:00
|
|
|
{#if loading_status}
|
|
|
|
<StatusTracker
|
2023-10-31 12:46:02 +08:00
|
|
|
autoscroll={gradio.autoscroll}
|
|
|
|
i18n={gradio.i18n}
|
2023-06-06 09:11:53 +08:00
|
|
|
{...loading_status}
|
|
|
|
show_progress={loading_status.show_progress === "hidden"
|
|
|
|
? "hidden"
|
|
|
|
: "minimal"}
|
2024-04-20 03:38:53 +08:00
|
|
|
on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
|
2023-06-06 09:11:53 +08:00
|
|
|
/>
|
|
|
|
{/if}
|
2023-06-16 05:58:31 +08:00
|
|
|
<div class="wrapper">
|
|
|
|
{#if show_label}
|
|
|
|
<BlockLabel
|
|
|
|
{show_label}
|
|
|
|
Icon={Chat}
|
2024-06-25 05:41:06 +08:00
|
|
|
float={true}
|
2023-06-16 05:58:31 +08:00
|
|
|
label={label || "Chatbot"}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
<ChatBot
|
2023-10-31 12:46:02 +08:00
|
|
|
i18n={gradio.i18n}
|
|
|
|
selectable={_selectable}
|
2023-09-02 07:20:55 +08:00
|
|
|
{likeable}
|
2023-07-06 08:50:17 +08:00
|
|
|
{show_share_button}
|
2023-06-16 05:58:31 +08:00
|
|
|
value={_value}
|
|
|
|
{latex_delimiters}
|
2023-09-23 02:53:09 +08:00
|
|
|
{render_markdown}
|
2024-06-14 22:43:35 +08:00
|
|
|
{theme_mode}
|
2023-06-16 05:58:31 +08:00
|
|
|
pending_message={loading_status?.status === "pending"}
|
2023-07-18 00:53:23 +08:00
|
|
|
{rtl}
|
2023-08-10 22:11:26 +08:00
|
|
|
{show_copy_button}
|
2023-08-24 04:48:10 +08:00
|
|
|
on:change={() => gradio.dispatch("change", value)}
|
|
|
|
on:select={(e) => gradio.dispatch("select", e.detail)}
|
2023-09-02 07:20:55 +08:00
|
|
|
on:like={(e) => gradio.dispatch("like", e.detail)}
|
2023-08-24 04:48:10 +08:00
|
|
|
on:share={(e) => gradio.dispatch("share", e.detail)}
|
|
|
|
on:error={(e) => gradio.dispatch("error", e.detail)}
|
2023-08-22 05:15:59 +08:00
|
|
|
{avatar_images}
|
2023-08-29 12:26:29 +08:00
|
|
|
{sanitize_html}
|
2023-08-29 08:48:52 +08:00
|
|
|
{bubble_full_width}
|
2023-10-03 11:44:58 +08:00
|
|
|
{line_breaks}
|
2023-10-03 01:29:20 +08:00
|
|
|
{layout}
|
2024-03-28 03:13:17 +08:00
|
|
|
{placeholder}
|
2024-06-14 22:43:35 +08:00
|
|
|
upload={gradio.client.upload}
|
|
|
|
_fetch={gradio.client.fetch}
|
|
|
|
load_component={gradio.load_component}
|
2022-06-02 01:02:18 +08:00
|
|
|
/>
|
2023-06-16 05:58:31 +08:00
|
|
|
</div>
|
2022-04-26 22:48:39 +08:00
|
|
|
</Block>
|
2023-06-16 05:58:31 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.wrapper {
|
|
|
|
display: flex;
|
|
|
|
position: relative;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: start;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|