123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <script lang="ts">
- import { getBackendConfig } from '$lib/apis';
- import { setDefaultPromptSuggestions } from '$lib/apis/configs';
- import { config, models, settings, user } from '$lib/stores';
- import { createEventDispatcher, onMount, getContext } from 'svelte';
- import { toast } from 'svelte-sonner';
- import Tooltip from '$lib/components/common/Tooltip.svelte';
- const dispatch = createEventDispatcher();
- const i18n = getContext('i18n');
- export let saveSettings: Function;
- // Addons
- let titleAutoGenerate = true;
- let responseAutoCopy = false;
- let widescreenMode = false;
- let splitLargeChunks = false;
- // Interface
- let defaultModelId = '';
- let showUsername = false;
- let chatBubble = true;
- let chatDirection: 'LTR' | 'RTL' = 'LTR';
- let showEmojiInCall = false;
- const toggleSplitLargeChunks = async () => {
- splitLargeChunks = !splitLargeChunks;
- saveSettings({ splitLargeChunks: splitLargeChunks });
- };
- const togglewidescreenMode = async () => {
- widescreenMode = !widescreenMode;
- saveSettings({ widescreenMode: widescreenMode });
- };
- const toggleChatBubble = async () => {
- chatBubble = !chatBubble;
- saveSettings({ chatBubble: chatBubble });
- };
- const toggleShowUsername = async () => {
- showUsername = !showUsername;
- saveSettings({ showUsername: showUsername });
- };
- 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';
- saveSettings({ chatDirection });
- };
- const updateInterfaceHandler = async () => {
- saveSettings({
- models: [defaultModelId]
- });
- };
- onMount(async () => {
- titleAutoGenerate = $settings?.title?.auto ?? true;
- responseAutoCopy = $settings.responseAutoCopy ?? false;
- showUsername = $settings.showUsername ?? false;
- showEmojiInCall = $settings.showEmojiInCall ?? false;
- chatBubble = $settings.chatBubble ?? true;
- widescreenMode = $settings.widescreenMode ?? false;
- splitLargeChunks = $settings.splitLargeChunks ?? false;
- chatDirection = $settings.chatDirection ?? 'LTR';
- defaultModelId = ($settings?.models ?? ['']).at(0);
- });
- </script>
- <form
- class="flex flex-col h-full justify-between space-y-3 text-sm"
- on:submit|preventDefault={() => {
- updateInterfaceHandler();
- dispatch('save');
- }}
- >
- <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>
- <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">
- <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>
- <div>
- <div class=" py-0.5 flex w-full justify-between">
- <div class=" self-center text-xs font-medium">{$i18n.t('Widescreen Mode')}</div>
- <button
- class="p-1 px-3 text-xs flex rounded transition"
- on:click={() => {
- togglewidescreenMode();
- }}
- type="button"
- >
- {#if widescreenMode === 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('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>
- </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>
- </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"
- >
- {#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>
- </div>
- <div class="flex justify-end text-sm font-medium">
- <button
- class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
- type="submit"
- >
- {$i18n.t('Save')}
- </button>
- </div>
- </form>
|