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

433 lines
11 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-06-16 22:32:26 +00:00
import { updateUserInfo } from '$lib/apis/users';
import { getUserPosition } from '$lib/utils';
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;
2024-06-17 08:31:22 +00:00
let backgroundImageUrl = null;
let inputFiles = null;
let filesInputElement;
// Addons
let titleAutoGenerate = true;
let responseAutoCopy = false;
2024-06-04 18:48:46 +00:00
let widescreenMode = false;
let splitLargeChunks = false;
2024-06-16 22:32:26 +00:00
let userLocation = 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 });
};
2024-06-16 22:32:26 +00:00
const toggleUserLocation = async () => {
userLocation = !userLocation;
if (userLocation) {
const position = await getUserPosition().catch((error) => {
toast.error(error.message);
return null;
});
if (position) {
await updateUserInfo(localStorage.token, { location: position });
toast.success('User location successfully retrieved.');
} else {
userLocation = false;
}
}
saveSettings({ userLocation });
};
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';
2024-06-16 22:32:26 +00:00
userLocation = $settings.userLocation ?? false;
defaultModelId = ($settings?.models ?? ['']).at(0);
2024-06-17 08:31:22 +00:00
backgroundImageUrl = $settings.backgroundImageUrl ?? null;
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-06-17 08:31:22 +00:00
<input
bind:this={filesInputElement}
bind:files={inputFiles}
type="file"
hidden
accept="image/*"
on:change={() => {
let reader = new FileReader();
reader.onload = (event) => {
let originalImageUrl = `${event.target.result}`;
backgroundImageUrl = originalImageUrl;
saveSettings({ backgroundImageUrl });
};
if (
inputFiles &&
inputFiles.length > 0 &&
['image/gif', 'image/webp', 'image/jpeg', 'image/png'].includes(inputFiles[0]['type'])
) {
reader.readAsDataURL(inputFiles[0]);
} else {
console.log(`Unsupported File Type '${inputFiles[0]['type']}'.`);
inputFiles = null;
}
}}
/>
<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[25rem] scrollbar-hidden">
<div class=" space-y-1 mb-3">
<div class="mb-2">
<div class="flex justify-between items-center text-xs">
<div class=" text-sm 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>
<hr class=" dark:border-gray-850" />
<div>
2024-06-17 08:31:22 +00:00
<div class=" mb-1.5 text-sm font-medium">{$i18n.t('UI')}</div>
2024-05-15 22:39:41 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
2024-06-17 08:31:22 +00:00
<div class=" self-center text-xs">{$i18n.t('Chat Bubble UI')}</div>
2024-05-15 22:39:41 +00:00
<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>
2024-06-17 08:31:22 +00:00
{#if !$settings.chatBubble}
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">
{$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}
2024-06-16 22:32:26 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
2024-06-17 08:31:22 +00:00
<div class=" self-center text-xs">{$i18n.t('Widescreen Mode')}</div>
2024-06-16 22:32:26 +00:00
<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">
2024-06-17 08:31:22 +00:00
<div class=" self-center text-xs">{$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>
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">
{$i18n.t('Fluidly stream large external response chunks')}
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
2024-06-17 08:31:22 +00:00
toggleSplitLargeChunks();
}}
type="button"
>
2024-06-17 08:31:22 +00:00
{#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 class=" py-0.5 flex w-full justify-between">
2024-06-17 08:31:22 +00:00
<div class=" self-center text-xs">
{$i18n.t('Chat Background Image')}
2024-03-02 21:53:41 +00:00
</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
2024-06-17 08:31:22 +00:00
if (backgroundImageUrl !== null) {
backgroundImageUrl = null;
saveSettings({ backgroundImageUrl });
} else {
filesInputElement.click();
}
}}
type="button"
>
2024-06-17 08:31:22 +00:00
{#if backgroundImageUrl !== null}
<span class="ml-2 self-center">{$i18n.t('Reset')}</span>
{:else}
2024-06-17 08:31:22 +00:00
<span class="ml-2 self-center">{$i18n.t('Upload')}</span>
{/if}
</button>
</div>
</div>
2024-02-10 00:00:39 +00:00
2024-06-17 08:31:22 +00:00
<div class=" my-1.5 text-sm font-medium">{$i18n.t('Chat')}</div>
2024-02-15 08:34:55 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
2024-06-17 08:31:22 +00:00
<div class=" self-center text-xs">{$i18n.t('Title Auto-Generation')}</div>
2024-02-15 08:34:55 +00:00
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
2024-06-17 08:31:22 +00:00
toggleTitleAutoGenerate();
2024-02-15 08:34:55 +00:00
}}
type="button"
>
2024-06-17 08:31:22 +00:00
{#if titleAutoGenerate === 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">
2024-06-17 08:31:22 +00:00
<div class=" self-center text-xs">
{$i18n.t('Response AutoCopy to Clipboard')}
</div>
2024-06-13 04:18:53 +00:00
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
2024-06-17 08:31:22 +00:00
toggleResponseAutoCopy();
2024-06-13 04:18:53 +00:00
}}
type="button"
>
2024-06-17 08:31:22 +00:00
{#if responseAutoCopy === true}
2024-06-13 04:18:53 +00:00
<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-06-17 08:31:22 +00:00
<div class=" self-center text-xs">{$i18n.t('Allow User Location')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
2024-06-17 08:31:22 +00:00
toggleUserLocation();
}}
type="button"
>
2024-06-17 08:31:22 +00:00
{#if userLocation === 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
2024-06-17 08:31:22 +00:00
<div class=" my-1.5 text-sm font-medium">{$i18n.t('Voice')}</div>
2024-06-17 08:31:22 +00:00
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">{$i18n.t('Display Emoji in Call')}</div>
2024-06-17 08:31:22 +00:00
<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>
</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>