2023-11-19 17:47:07 -08:00
|
|
|
<script lang="ts">
|
2024-08-19 16:49:40 +02:00
|
|
|
import { models, showSettings, settings, user, mobile, config } from '$lib/stores';
|
2024-03-01 08:10:36 +03:30
|
|
|
import { onMount, tick, getContext } from 'svelte';
|
2024-03-01 10:18:07 +01:00
|
|
|
import { toast } from 'svelte-sonner';
|
2024-03-24 23:03:26 -07:00
|
|
|
import Selector from './ModelSelector/Selector.svelte';
|
2024-03-29 17:20:07 -07:00
|
|
|
import Tooltip from '../common/Tooltip.svelte';
|
2023-11-19 17:47:07 -08:00
|
|
|
|
2024-05-26 22:47:42 -07:00
|
|
|
import { setDefaultModels } from '$lib/apis/configs';
|
|
|
|
|
import { updateUserSettings } from '$lib/apis/users';
|
|
|
|
|
|
2024-03-01 08:10:36 +03:30
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
2023-11-19 17:47:07 -08:00
|
|
|
export let selectedModels = [''];
|
|
|
|
|
export let disabled = false;
|
|
|
|
|
|
2024-05-02 01:15:58 -07:00
|
|
|
export let showSetDefault = true;
|
|
|
|
|
|
2024-01-02 17:26:19 -08:00
|
|
|
const saveDefaultModel = async () => {
|
2023-12-29 23:35:08 -08:00
|
|
|
const hasEmptyModel = selectedModels.filter((it) => it === '');
|
|
|
|
|
if (hasEmptyModel.length) {
|
2024-03-03 00:08:51 +03:30
|
|
|
toast.error($i18n.t('Choose a model before saving...'));
|
2023-12-28 18:06:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2023-11-19 17:47:07 -08:00
|
|
|
settings.set({ ...$settings, models: selectedModels });
|
2024-05-26 22:47:42 -07:00
|
|
|
await updateUserSettings(localStorage.token, { ui: $settings });
|
2024-01-02 17:26:19 -08:00
|
|
|
|
2024-03-03 00:08:51 +03:30
|
|
|
toast.success($i18n.t('Default model updated'));
|
2023-11-19 17:47:07 -08:00
|
|
|
};
|
2024-01-02 16:06:11 -08:00
|
|
|
|
|
|
|
|
$: if (selectedModels.length > 0 && $models.length > 0) {
|
|
|
|
|
selectedModels = selectedModels.map((model) =>
|
2024-02-22 04:12:26 -08:00
|
|
|
$models.map((m) => m.id).includes(model) ? model : ''
|
2024-01-02 16:06:11 -08:00
|
|
|
);
|
|
|
|
|
}
|
2023-11-19 17:47:07 -08:00
|
|
|
</script>
|
|
|
|
|
|
2024-07-08 16:55:12 -07:00
|
|
|
<div class="flex flex-col w-full items-start">
|
2023-11-19 17:47:07 -08:00
|
|
|
{#each selectedModels as selectedModel, selectedModelIdx}
|
2024-05-02 12:33:04 -07:00
|
|
|
<div class="flex w-full max-w-fit">
|
2024-03-24 15:28:36 -07:00
|
|
|
<div class="overflow-hidden w-full">
|
2024-05-02 12:33:04 -07:00
|
|
|
<div class="mr-1 max-w-full">
|
2024-03-24 23:03:26 -07:00
|
|
|
<Selector
|
2024-03-24 15:28:36 -07:00
|
|
|
placeholder={$i18n.t('Select a model')}
|
2024-05-24 03:02:56 -07:00
|
|
|
items={$models.map((model) => ({
|
|
|
|
|
value: model.id,
|
|
|
|
|
label: model.name,
|
|
|
|
|
model: model
|
|
|
|
|
}))}
|
2024-08-19 16:49:40 +02:00
|
|
|
showTemporaryChatControl={$user.role === 'user'
|
|
|
|
|
? ($config?.permissions?.chat?.temporary ?? true)
|
|
|
|
|
: true}
|
2024-03-24 15:28:36 -07:00
|
|
|
bind:value={selectedModel}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2023-11-19 17:47:07 -08:00
|
|
|
|
|
|
|
|
{#if selectedModelIdx === 0}
|
2024-03-29 17:20:07 -07:00
|
|
|
<div class=" self-center mr-2 disabled:text-gray-600 disabled:hover:text-gray-600">
|
2024-04-30 10:46:16 +02:00
|
|
|
<Tooltip content={$i18n.t('Add Model')}>
|
2024-03-29 17:20:07 -07:00
|
|
|
<button
|
|
|
|
|
class=" "
|
|
|
|
|
{disabled}
|
|
|
|
|
on:click={() => {
|
|
|
|
|
selectedModels = [...selectedModels, ''];
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
fill="none"
|
|
|
|
|
viewBox="0 0 24 24"
|
2024-05-02 12:33:04 -07:00
|
|
|
stroke-width="2"
|
2024-03-29 17:20:07 -07:00
|
|
|
stroke="currentColor"
|
2024-05-02 12:33:04 -07:00
|
|
|
class="size-3.5"
|
2024-03-29 17:20:07 -07:00
|
|
|
>
|
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6v12m6-6H6" />
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2023-11-19 17:47:07 -08:00
|
|
|
{:else}
|
2024-03-29 17:20:07 -07:00
|
|
|
<div class=" self-center disabled:text-gray-600 disabled:hover:text-gray-600 mr-2">
|
2024-04-30 10:46:16 +02:00
|
|
|
<Tooltip content={$i18n.t('Remove Model')}>
|
2024-03-29 17:20:07 -07:00
|
|
|
<button
|
|
|
|
|
{disabled}
|
|
|
|
|
on:click={() => {
|
|
|
|
|
selectedModels.splice(selectedModelIdx, 1);
|
|
|
|
|
selectedModels = selectedModels;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<svg
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
fill="none"
|
|
|
|
|
viewBox="0 0 24 24"
|
2024-05-02 12:33:04 -07:00
|
|
|
stroke-width="2"
|
2024-03-29 17:20:07 -07:00
|
|
|
stroke="currentColor"
|
2024-05-02 12:33:04 -07:00
|
|
|
class="size-3.5"
|
2024-03-29 17:20:07 -07:00
|
|
|
>
|
|
|
|
|
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 12h-15" />
|
|
|
|
|
</svg>
|
|
|
|
|
</button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2023-11-19 17:47:07 -08:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-05-14 20:16:22 -10:00
|
|
|
{#if showSetDefault && !$mobile}
|
2024-07-08 14:32:51 -07:00
|
|
|
<div class="text-left mt-0.5 ml-1 text-[0.7rem] text-gray-500 font-primary">
|
2024-05-02 01:15:58 -07:00
|
|
|
<button on:click={saveDefaultModel}> {$i18n.t('Set as default')}</button>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|