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';
|
|
|
|
import { sanitizeResponseContent, findWordIndices } from '$lib/utils';
|
|
|
|
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';
|
2024-08-15 14:54:16 +00:00
|
|
|
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 availableToolIds = [];
|
|
|
|
export let selectedToolIds = [];
|
|
|
|
export let webSearchEnabled = false;
|
|
|
|
|
|
|
|
let models = [];
|
|
|
|
|
|
|
|
const selectSuggestionPrompt = async (p) => {
|
|
|
|
let text = p;
|
|
|
|
|
|
|
|
if (p.includes('{{CLIPBOARD}}')) {
|
|
|
|
const clipboardText = await navigator.clipboard.readText().catch((err) => {
|
|
|
|
toast.error($i18n.t('Failed to read clipboard contents'));
|
|
|
|
return '{{CLIPBOARD}}';
|
|
|
|
});
|
|
|
|
|
|
|
|
text = p.replaceAll('{{CLIPBOARD}}', clipboardText);
|
|
|
|
|
|
|
|
console.log('Clipboard text:', clipboardText, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
prompt = text;
|
|
|
|
|
|
|
|
console.log(prompt);
|
|
|
|
await tick();
|
2023-12-30 07:03:48 +00:00
|
|
|
|
2024-10-05 10:07:56 +00:00
|
|
|
const chatInputElement = document.getElementById('chat-textarea');
|
|
|
|
if (chatInputElement) {
|
|
|
|
chatInputElement.style.height = '';
|
|
|
|
chatInputElement.style.height = Math.min(chatInputElement.scrollHeight, 200) + 'px';
|
|
|
|
chatInputElement.focus();
|
|
|
|
|
|
|
|
const words = findWordIndices(prompt);
|
|
|
|
|
|
|
|
if (words.length > 0) {
|
|
|
|
const word = words.at(0);
|
|
|
|
chatInputElement.setSelectionRange(word?.startIndex, word.endIndex + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await tick();
|
|
|
|
};
|
2024-04-30 21:56:06 +00:00
|
|
|
|
2024-05-02 06:41:12 +00:00
|
|
|
let mounted = false;
|
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));
|
2024-05-24 10:02:56 +00:00
|
|
|
|
2024-05-02 06:41:12 +00:00
|
|
|
onMount(() => {
|
|
|
|
mounted = true;
|
|
|
|
});
|
2023-12-30 07:03:48 +00:00
|
|
|
</script>
|
|
|
|
|
2024-05-02 06:41:12 +00:00
|
|
|
{#key mounted}
|
2024-10-05 10:29:55 +00:00
|
|
|
<div class="m-auto w-full max-w-6xl px-2 xl:px-20 translate-y-6 text-center">
|
2024-08-15 14:54:16 +00:00
|
|
|
{#if $temporaryChatEnabled}
|
|
|
|
<Tooltip
|
|
|
|
content="This chat won't appear in history and your messages will not be saved."
|
2024-10-05 10:07:56 +00:00
|
|
|
className="w-full flex justify-center mb-0.5"
|
2024-10-05 22:55:30 +00:00
|
|
|
placement="top"
|
2024-08-15 14:54:16 +00:00
|
|
|
>
|
|
|
|
<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" /> Temporary Chat
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
{/if}
|
|
|
|
|
2024-04-30 23:00:44 +00:00
|
|
|
<div
|
2024-10-05 10:07:56 +00:00
|
|
|
class="w-full text-3xl text-gray-800 dark:text-gray-100 font-medium text-center flex items-center gap-4 font-primary"
|
2024-04-30 23:00:44 +00:00
|
|
|
>
|
2024-10-05 10:07:56 +00:00
|
|
|
<div class="w-full flex flex-col justify-center items-center">
|
2024-10-06 18:54:57 +00:00
|
|
|
<div class="flex flex-col md:flex-row justify-center gap-2 md:gap-3.5 w-fit">
|
2024-10-05 10:15:39 +00:00
|
|
|
<div class="flex flex-shrink-0 justify-center">
|
2024-10-05 10:24:00 +00:00
|
|
|
<div class="flex -space-x-4 mb-0.5" in:fade={{ duration: 100 }}>
|
2024-10-05 10:07:56 +00:00
|
|
|
{#each models as model, modelIdx}
|
2024-10-06 18:54:57 +00:00
|
|
|
<Tooltip
|
|
|
|
content={(models[modelIdx]?.info?.meta?.tags ?? [])
|
|
|
|
.map((tag) => tag.name.toUpperCase())
|
|
|
|
.join(', ')}
|
|
|
|
placement="top"
|
2024-10-05 10:07:56 +00:00
|
|
|
>
|
2024-10-06 18:54:57 +00:00
|
|
|
<button
|
|
|
|
on:click={() => {
|
|
|
|
selectedModelIdx = modelIdx;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
crossorigin="anonymous"
|
|
|
|
src={model?.info?.meta?.profile_image_url ??
|
|
|
|
($i18n.language === 'dg-DG'
|
|
|
|
? `/doge.png`
|
|
|
|
: `${WEBUI_BASE_URL}/static/favicon.png`)}
|
|
|
|
class=" size-[2.5rem] rounded-full border-[1px] border-gray-200 dark:border-none"
|
|
|
|
alt="logo"
|
|
|
|
draggable="false"
|
|
|
|
/>
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2024-10-05 10:07:56 +00:00
|
|
|
{/each}
|
2024-05-02 06:41:12 +00:00
|
|
|
</div>
|
2024-10-05 10:07:56 +00:00
|
|
|
</div>
|
|
|
|
|
2024-10-05 10:24:00 +00:00
|
|
|
<div class=" capitalize line-clamp-1 text-3xl md:text-4xl" in:fade={{ duration: 100 }}>
|
2024-10-05 10:07:56 +00:00
|
|
|
{#if models[selectedModelIdx]?.info}
|
|
|
|
{models[selectedModelIdx]?.info?.name}
|
|
|
|
{:else}
|
|
|
|
{$i18n.t('Hello, {{name}}', { name: $user.name })}
|
|
|
|
{/if}
|
|
|
|
</div>
|
2024-10-06 18:54:57 +00:00
|
|
|
</div>
|
2024-10-05 10:07:56 +00:00
|
|
|
|
2024-10-06 04:14:35 +00:00
|
|
|
<div class="flex mt-1 mb-2">
|
2024-10-05 10:24:00 +00:00
|
|
|
<div in:fade={{ duration: 100, delay: 50 }}>
|
2024-10-05 10:07:56 +00:00
|
|
|
{#if models[selectedModelIdx]?.info?.meta?.description ?? null}
|
2024-10-06 04:14:35 +00:00
|
|
|
<Tooltip
|
|
|
|
className=" w-fit"
|
|
|
|
content={marked.parse(
|
|
|
|
sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description ?? '')
|
2024-10-05 10:07:56 +00:00
|
|
|
)}
|
2024-10-06 04:14:35 +00:00
|
|
|
placement="top"
|
|
|
|
>
|
|
|
|
<div
|
2024-10-06 04:16:20 +00:00
|
|
|
class="mt-0.5 px-2 text-sm font-normal text-gray-500 dark:text-gray-400 line-clamp-2 max-w-xl markdown"
|
2024-10-06 04:14:35 +00:00
|
|
|
>
|
|
|
|
{@html marked.parse(
|
|
|
|
sanitizeResponseContent(models[selectedModelIdx]?.info?.meta?.description)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
|
2024-10-05 10:07:56 +00:00
|
|
|
{#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}
|
2024-05-02 06:41:12 +00:00
|
|
|
{/if}
|
2024-10-05 10:07:56 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2024-10-05 22:47:51 +00:00
|
|
|
<div
|
2024-10-06 23:40:27 +00:00
|
|
|
class="text-base font-normal xl:translate-x-6 lg:max-w-3xl w-full py-3 {atSelectedModel
|
2024-10-05 22:47:51 +00:00
|
|
|
? 'mt-2'
|
|
|
|
: ''}"
|
|
|
|
>
|
2024-10-05 10:07:56 +00:00
|
|
|
<MessageInput
|
|
|
|
{history}
|
|
|
|
{selectedModels}
|
|
|
|
bind:files
|
|
|
|
bind:prompt
|
|
|
|
bind:autoScroll
|
|
|
|
bind:selectedToolIds
|
|
|
|
bind:webSearchEnabled
|
|
|
|
bind:atSelectedModel
|
|
|
|
{availableToolIds}
|
|
|
|
{transparentBackground}
|
|
|
|
{stopResponse}
|
|
|
|
{createMessagePair}
|
|
|
|
placeholder={$i18n.t('How can I help you today?')}
|
2024-10-08 01:19:13 +00:00
|
|
|
on:upload={(e) => {
|
|
|
|
dispatch('upload', e.detail);
|
|
|
|
}}
|
2024-10-05 10:07:56 +00:00
|
|
|
on:submit={(e) => {
|
|
|
|
dispatch('submit', e.detail);
|
|
|
|
}}
|
|
|
|
/>
|
2024-05-02 06:41:12 +00:00
|
|
|
</div>
|
2024-04-30 21:56:06 +00:00
|
|
|
</div>
|
2023-12-30 07:03:48 +00:00
|
|
|
</div>
|
2024-10-05 10:24:00 +00:00
|
|
|
<div class="mx-auto max-w-2xl font-primary" in:fade={{ duration: 200, delay: 200 }}>
|
2024-10-05 17:23:47 +00:00
|
|
|
<div class="mx-5">
|
2024-10-05 10:07:56 +00:00
|
|
|
<Suggestions
|
|
|
|
suggestionPrompts={models[selectedModelIdx]?.info?.meta?.suggestion_prompts ??
|
|
|
|
$config?.default_prompt_suggestions ??
|
|
|
|
[]}
|
|
|
|
on:select={(e) => {
|
|
|
|
selectSuggestionPrompt(e.detail);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-04-30 23:00:44 +00:00
|
|
|
</div>
|
2023-12-30 07:03:48 +00:00
|
|
|
</div>
|
2024-05-02 06:41:12 +00:00
|
|
|
{/key}
|