open-webui/src/lib/components/chat/Placeholder.svelte

230 lines
6.6 KiB
Svelte
Raw Normal View History

2023-12-30 07:03:48 +00:00
<script lang="ts">
2024-10-05 10:07:56 +00:00
import { toast } from 'svelte-sonner';
2024-06-15 10:32:18 +00:00
import { marked } from 'marked';
2024-10-05 10:07:56 +00:00
import { onMount, getContext, tick, createEventDispatcher } from 'svelte';
2024-05-02 06:41:12 +00:00
import { blur, fade } from 'svelte/transition';
2024-10-05 10:07:56 +00:00
const dispatch = createEventDispatcher();
import { config, user, models as _models, temporaryChatEnabled } from '$lib/stores';
2025-04-04 15:11:54 +00:00
import { sanitizeResponseContent, extractCurlyBraceWords } from '$lib/utils';
2024-10-05 10:07:56 +00:00
import { WEBUI_BASE_URL } from '$lib/constants';
2024-10-06 18:45:13 +00:00
import Suggestions from './Suggestions.svelte';
2024-06-17 09:26:07 +00:00
import Tooltip from '$lib/components/common/Tooltip.svelte';
import EyeSlash from '$lib/components/icons/EyeSlash.svelte';
2024-10-06 18:45:13 +00:00
import MessageInput from './MessageInput.svelte';
2024-03-01 04:40:36 +00:00
const i18n = getContext('i18n');
2023-12-30 07:03:48 +00:00
2024-10-05 10:07:56 +00:00
export let transparentBackground = false;
export let createMessagePair: Function;
export let stopResponse: Function;
export let autoScroll = false;
export let atSelectedModel: Model | undefined;
export let selectedModels: [''];
export let history;
export let prompt = '';
export let files = [];
export let messageInput = null;
2024-11-17 01:49:13 +00:00
2024-10-05 10:07:56 +00:00
export let selectedToolIds = [];
2025-05-16 18:43:42 +00:00
export let selectedFilterIds = [];
export let showCommands = false;
2025-01-16 07:32:13 +00:00
export let imageGenerationEnabled = false;
2025-02-03 09:14:38 +00:00
export let codeInterpreterEnabled = false;
2024-10-05 10:07:56 +00:00
export let webSearchEnabled = false;
2025-07-04 19:40:31 +00:00
export let onSelect = (e) => {};
export let toolServers = [];
2024-10-05 10:07:56 +00:00
let models = [];
2023-12-30 07:03:48 +00:00
let selectedModelIdx = 0;
2024-10-05 10:07:56 +00:00
$: if (selectedModels.length > 0) {
2023-12-30 07:03:48 +00:00
selectedModelIdx = models.length - 1;
}
2024-05-02 06:41:12 +00:00
2024-10-05 10:07:56 +00:00
$: models = selectedModels.map((id) => $_models.find((m) => m.id === id));
2025-04-04 15:11:54 +00:00
2024-11-19 06:49:38 +00:00
onMount(() => {});
2023-12-30 07:03:48 +00:00
</script>
2025-02-05 09:14:46 +00:00
<div class="m-auto w-full max-w-6xl px-2 @2xl:px-20 translate-y-6 py-24 text-center">
2024-11-19 06:49:38 +00:00
{#if $temporaryChatEnabled}
2025-04-04 15:11:54 +00:00
<Tooltip
content={$i18n.t("This chat won't appear in history and your messages will not be saved.")}
2025-04-04 15:11:54 +00:00
className="w-full flex justify-center mb-0.5"
placement="top"
>
<div class="flex items-center gap-2 text-gray-500 font-medium text-lg my-2 w-fit">
<EyeSlash strokeWidth="2.5" className="size-5" />{$i18n.t('Temporary Chat')}
</div>
</Tooltip>
2024-11-19 06:49:38 +00:00
{/if}
<div
2025-03-04 05:10:15 +00:00
class="w-full text-3xl text-gray-800 dark:text-gray-100 text-center flex items-center gap-4 font-primary"
2024-11-19 06:49:38 +00:00
>
<div class="w-full flex flex-col justify-center items-center">
<div class="flex flex-row justify-center gap-3 @sm:gap-3.5 w-fit px-5 max-w-xl">
2025-02-16 03:27:25 +00:00
<div class="flex shrink-0 justify-center">
2024-11-19 06:49:38 +00:00
<div class="flex -space-x-4 mb-0.5" in:fade={{ duration: 100 }}>
{#each models as model, modelIdx}
2024-10-06 04:14:35 +00:00
<Tooltip
2024-11-19 06:49:38 +00:00
content={(models[modelIdx]?.info?.meta?.tags ?? [])
.map((tag) => tag.name.toUpperCase())
.join(', ')}
2024-10-06 04:14:35 +00:00
placement="top"
>
2024-11-19 06:49:38 +00:00
<button
aria-hidden={models.length <= 1}
aria-label={$i18n.t('Get information on {{name}} in the UI', {
name: models[modelIdx]?.name
})}
2024-11-19 06:49:38 +00:00
on:click={() => {
selectedModelIdx = modelIdx;
}}
2024-10-06 04:14:35 +00:00
>
2024-11-19 06:49:38 +00:00
<img
crossorigin="anonymous"
src={model?.info?.meta?.profile_image_url ??
($i18n.language === 'dg-DG'
? `${WEBUI_BASE_URL}/doge.png`
2024-11-19 06:49:38 +00:00
: `${WEBUI_BASE_URL}/static/favicon.png`)}
2025-03-05 05:24:17 +00:00
class=" size-9 @sm:size-10 rounded-full border-[1px] border-gray-100 dark:border-none"
aria-hidden="true"
2024-11-19 06:49:38 +00:00
draggable="false"
/>
</button>
2024-10-06 04:14:35 +00:00
</Tooltip>
2024-11-19 06:49:38 +00:00
{/each}
2024-10-05 10:07:56 +00:00
</div>
</div>
<div
class=" text-3xl @sm:text-3xl line-clamp-1 flex items-center"
in:fade={{ duration: 100 }}
>
2024-11-19 06:49:38 +00:00
{#if models[selectedModelIdx]?.name}
<Tooltip
content={models[selectedModelIdx]?.name}
placement="top"
className=" flex items-center "
>
<span class="line-clamp-1">
{models[selectedModelIdx]?.name}
</span>
</Tooltip>
2024-11-19 06:49:38 +00:00
{:else}
2025-04-01 03:32:12 +00:00
{$i18n.t('Hello, {{name}}', { name: $user?.name })}
2024-11-19 06:49:38 +00:00
{/if}
2024-05-02 06:41:12 +00:00
</div>
2024-04-30 21:56:06 +00:00
</div>
2024-11-19 06:49:38 +00:00
<div class="flex mt-1 mb-2">
<div in:fade={{ duration: 100, delay: 50 }}>
{#if models[selectedModelIdx]?.info?.meta?.description ?? null}
<Tooltip
className=" w-fit"
content={marked.parse(
sanitizeResponseContent(
models[selectedModelIdx]?.info?.meta?.description ?? ''
).replaceAll('\n', '<br>')
2024-11-19 06:49:38 +00:00
)}
placement="top"
>
<div
class="mt-0.5 px-2 text-sm font-normal text-gray-500 dark:text-gray-400 line-clamp-2 max-w-xl markdown"
>
{@html marked.parse(
sanitizeResponseContent(
models[selectedModelIdx]?.info?.meta?.description ?? ''
).replaceAll('\n', '<br>')
2024-11-19 06:49:38 +00:00
)}
</div>
</Tooltip>
{#if models[selectedModelIdx]?.info?.meta?.user}
<div class="mt-0.5 text-sm font-normal text-gray-400 dark:text-gray-500">
By
{#if models[selectedModelIdx]?.info?.meta?.user.community}
<a
href="https://openwebui.com/m/{models[selectedModelIdx]?.info?.meta?.user
.username}"
>{models[selectedModelIdx]?.info?.meta?.user.name
? models[selectedModelIdx]?.info?.meta?.user.name
: `@${models[selectedModelIdx]?.info?.meta?.user.username}`}</a
>
{:else}
{models[selectedModelIdx]?.info?.meta?.user.name}
{/if}
</div>
{/if}
{/if}
</div>
</div>
2025-02-05 09:14:46 +00:00
<div class="text-base font-normal @md:max-w-3xl w-full py-3 {atSelectedModel ? 'mt-2' : ''}">
2024-11-19 06:49:38 +00:00
<MessageInput
bind:this={messageInput}
2024-11-19 06:49:38 +00:00
{history}
{selectedModels}
bind:files
bind:prompt
bind:autoScroll
bind:selectedToolIds
2025-05-16 18:43:42 +00:00
bind:selectedFilterIds
2025-01-16 07:32:13 +00:00
bind:imageGenerationEnabled
2025-02-03 09:14:38 +00:00
bind:codeInterpreterEnabled
2024-11-19 06:49:38 +00:00
bind:webSearchEnabled
bind:atSelectedModel
bind:showCommands
{toolServers}
2024-11-19 06:49:38 +00:00
{transparentBackground}
{stopResponse}
{createMessagePair}
placeholder={$i18n.t('How can I help you today?')}
2025-05-06 21:48:54 +00:00
onChange={(input) => {
2025-06-16 08:46:04 +00:00
if (!$temporaryChatEnabled) {
if (input.prompt !== null) {
sessionStorage.setItem(`chat-input`, JSON.stringify(input));
2025-06-16 08:46:04 +00:00
} else {
sessionStorage.removeItem(`chat-input`);
2025-06-16 08:46:04 +00:00
}
2025-05-06 21:48:54 +00:00
}
}}
2024-11-19 06:49:38 +00:00
on:upload={(e) => {
dispatch('upload', e.detail);
}}
on:submit={(e) => {
dispatch('submit', e.detail);
2024-10-05 10:07:56 +00:00
}}
/>
</div>
2024-04-30 23:00:44 +00:00
</div>
2023-12-30 07:03:48 +00:00
</div>
2025-05-23 21:45:55 +00:00
<div class="mx-auto max-w-2xl font-primary mt-2" in:fade={{ duration: 200, delay: 200 }}>
2024-11-19 06:49:38 +00:00
<div class="mx-5">
<Suggestions
2025-02-25 09:46:08 +00:00
suggestionPrompts={atSelectedModel?.info?.meta?.suggestion_prompts ??
models[selectedModelIdx]?.info?.meta?.suggestion_prompts ??
2024-11-19 06:49:38 +00:00
$config?.default_prompt_suggestions ??
[]}
2025-02-04 08:14:02 +00:00
inputValue={prompt}
2025-07-04 19:40:31 +00:00
{onSelect}
2024-11-19 06:49:38 +00:00
/>
</div>
</div>
</div>