open-webui/src/lib/components/chat/Settings/Interface.svelte

325 lines
8.4 KiB
Svelte
Raw Normal View History

2024-02-05 09:58:54 +00:00
<script lang="ts">
import { getBackendConfig } from '$lib/apis';
import { setDefaultPromptSuggestions } from '$lib/apis/configs';
import { config, models, settings, user } from '$lib/stores';
2024-03-01 04:40:36 +00:00
import { createEventDispatcher, onMount, getContext } from 'svelte';
2024-03-01 09:18:07 +00:00
import { toast } from 'svelte-sonner';
import Tooltip from '$lib/components/common/Tooltip.svelte';
2024-02-05 09:58:54 +00:00
const dispatch = createEventDispatcher();
2024-03-01 04:40:36 +00:00
const i18n = getContext('i18n');
export let saveSettings: Function;
// Addons
let titleAutoGenerate = true;
let responseAutoCopy = false;
2024-06-04 18:48:46 +00:00
let widescreenMode = false;
let splitLargeChunks = false;
2024-02-05 09:58:54 +00:00
// Interface
let defaultModelId = '';
let showUsername = false;
2024-06-13 04:18:53 +00:00
2024-05-15 22:39:41 +00:00
let chatBubble = true;
let chatDirection: 'LTR' | 'RTL' = 'LTR';
2024-06-13 04:18:53 +00:00
let showEmojiInCall = false;
const toggleSplitLargeChunks = async () => {
splitLargeChunks = !splitLargeChunks;
saveSettings({ splitLargeChunks: splitLargeChunks });
};
2024-06-04 18:48:46 +00:00
const togglewidescreenMode = async () => {
widescreenMode = !widescreenMode;
saveSettings({ widescreenMode: widescreenMode });
2024-02-15 08:34:55 +00:00
};
2024-05-15 22:39:41 +00:00
const toggleChatBubble = async () => {
chatBubble = !chatBubble;
saveSettings({ chatBubble: chatBubble });
};
const toggleShowUsername = async () => {
showUsername = !showUsername;
saveSettings({ showUsername: showUsername });
};
2024-06-13 04:18:53 +00:00
const toggleEmojiInCall = async () => {
showEmojiInCall = !showEmojiInCall;
saveSettings({ showEmojiInCall: showEmojiInCall });
};
const toggleTitleAutoGenerate = async () => {
titleAutoGenerate = !titleAutoGenerate;
saveSettings({
title: {
...$settings.title,
auto: titleAutoGenerate
}
});
};
const toggleResponseAutoCopy = async () => {
const permission = await navigator.clipboard
.readText()
.then(() => {
return 'granted';
})
.catch(() => {
return '';
});
console.log(permission);
if (permission === 'granted') {
responseAutoCopy = !responseAutoCopy;
saveSettings({ responseAutoCopy: responseAutoCopy });
} else {
toast.error(
'Clipboard write permission denied. Please check your browser settings to grant the necessary access.'
);
}
};
const toggleChangeChatDirection = async () => {
chatDirection = chatDirection === 'LTR' ? 'RTL' : 'LTR';
2024-05-18 22:02:47 +00:00
saveSettings({ chatDirection });
};
2024-02-05 09:58:54 +00:00
const updateInterfaceHandler = async () => {
saveSettings({
models: [defaultModelId]
});
2024-02-05 09:58:54 +00:00
};
onMount(async () => {
2024-05-27 05:47:42 +00:00
titleAutoGenerate = $settings?.title?.auto ?? true;
2024-06-13 04:18:53 +00:00
2024-05-27 05:47:42 +00:00
responseAutoCopy = $settings.responseAutoCopy ?? false;
showUsername = $settings.showUsername ?? false;
2024-06-13 04:18:53 +00:00
showEmojiInCall = $settings.showEmojiInCall ?? false;
2024-05-27 05:47:42 +00:00
chatBubble = $settings.chatBubble ?? true;
2024-06-04 18:48:46 +00:00
widescreenMode = $settings.widescreenMode ?? false;
2024-05-27 05:47:42 +00:00
splitLargeChunks = $settings.splitLargeChunks ?? false;
chatDirection = $settings.chatDirection ?? 'LTR';
defaultModelId = ($settings?.models ?? ['']).at(0);
2024-02-05 09:58:54 +00:00
});
</script>
<form
class="flex flex-col h-full justify-between space-y-3 text-sm"
on:submit|preventDefault={() => {
updateInterfaceHandler();
dispatch('save');
}}
>
2024-05-15 22:55:13 +00:00
<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[25rem]">
<div>
<div class=" mb-1 text-sm font-medium">{$i18n.t('WebUI Add-ons')}</div>
2024-05-15 22:39:41 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Chat Bubble UI')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleChatBubble();
}}
type="button"
>
{#if chatBubble === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Title Auto-Generation')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleTitleAutoGenerate();
}}
type="button"
>
{#if titleAutoGenerate === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
<div>
<div class=" py-0.5 flex w-full justify-between">
2024-03-02 21:53:41 +00:00
<div class=" self-center text-xs font-medium">
{$i18n.t('Response AutoCopy to Clipboard')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleResponseAutoCopy();
}}
type="button"
>
{#if responseAutoCopy === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
2024-02-10 00:00:39 +00:00
2024-02-15 08:34:55 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
2024-06-04 18:48:46 +00:00
<div class=" self-center text-xs font-medium">{$i18n.t('Widescreen Mode')}</div>
2024-02-15 08:34:55 +00:00
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
2024-06-04 18:48:46 +00:00
togglewidescreenMode();
2024-02-15 08:34:55 +00:00
}}
type="button"
>
2024-06-04 18:48:46 +00:00
{#if widescreenMode === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
2024-02-15 08:34:55 +00:00
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
2024-02-15 08:34:55 +00:00
{/if}
</button>
</div>
</div>
2024-06-13 04:18:53 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Display Emoji in Call')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleEmojiInCall();
}}
type="button"
>
{#if showEmojiInCall === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
{#if !$settings.chatBubble}
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">
{$i18n.t('Display the username instead of You in the Chat')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleShowUsername();
}}
type="button"
>
{#if showUsername === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
2024-02-10 00:00:39 +00:00
</div>
</div>
{/if}
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">
{$i18n.t('Fluidly stream large external response chunks')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleSplitLargeChunks();
}}
type="button"
>
{#if splitLargeChunks === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
{/if}
</button>
</div>
</div>
2024-02-05 09:58:54 +00:00
</div>
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('Chat direction')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={toggleChangeChatDirection}
type="button"
>
2024-05-18 22:02:47 +00:00
{#if chatDirection === 'LTR'}
<span class="ml-2 self-center">{$i18n.t('LTR')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('RTL')}</span>
{/if}
</button>
</div>
</div>
<hr class=" dark:border-gray-850" />
<div class=" space-y-1 mb-3">
<div class="mb-2">
<div class="flex justify-between items-center text-xs">
<div class=" text-xs font-medium">{$i18n.t('Default Model')}</div>
</div>
</div>
<div class="flex-1 mr-2">
<select
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={defaultModelId}
placeholder="Select a model"
>
<option value="" disabled selected>{$i18n.t('Select a model')}</option>
{#each $models.filter((model) => model.id) as model}
<option value={model.id} class="bg-gray-100 dark:bg-gray-700">{model.name}</option>
{/each}
</select>
</div>
</div>
2024-02-05 09:58:54 +00:00
</div>
2024-03-16 09:24:32 +00:00
<div class="flex justify-end text-sm font-medium">
2024-02-05 09:58:54 +00:00
<button
2024-03-10 06:02:27 +00:00
class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
2024-02-05 09:58:54 +00:00
type="submit"
>
2024-03-04 08:53:56 +00:00
{$i18n.t('Save')}
2024-02-05 09:58:54 +00:00
</button>
</div>
</form>