mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-07 02:58:21 +00:00
refac
This commit is contained in:
parent
67e725c198
commit
a3a2e42ee0
3 changed files with 45 additions and 32 deletions
|
|
@ -106,7 +106,6 @@
|
||||||
import { createOpenAITextStream } from '$lib/apis/streaming';
|
import { createOpenAITextStream } from '$lib/apis/streaming';
|
||||||
import { getFunctions } from '$lib/apis/functions';
|
import { getFunctions } from '$lib/apis/functions';
|
||||||
import { initiateOAuthRedirect } from '$lib/apis/configs';
|
import { initiateOAuthRedirect } from '$lib/apis/configs';
|
||||||
import { updateFolderById } from '$lib/apis/folders';
|
|
||||||
|
|
||||||
import Banner from '../common/Banner.svelte';
|
import Banner from '../common/Banner.svelte';
|
||||||
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
||||||
|
|
@ -1548,24 +1547,6 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const savedModelIds = async () => {
|
|
||||||
if (
|
|
||||||
$selectedFolder &&
|
|
||||||
selectedModels.filter((modelId) => modelId !== '').length > 0 &&
|
|
||||||
!equal($selectedFolder?.data?.model_ids, selectedModels)
|
|
||||||
) {
|
|
||||||
const res = await updateFolderById(localStorage.token, $selectedFolder.id, {
|
|
||||||
data: {
|
|
||||||
model_ids: selectedModels
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$: if (selectedModels !== null) {
|
|
||||||
savedModelIds();
|
|
||||||
}
|
|
||||||
|
|
||||||
const stopAudio = () => {
|
const stopAudio = () => {
|
||||||
try {
|
try {
|
||||||
speechSynthesis.cancel();
|
speechSynthesis.cancel();
|
||||||
|
|
@ -1646,14 +1627,11 @@
|
||||||
const selectedFolderSubscribe = selectedFolder.subscribe(async (folder) => {
|
const selectedFolderSubscribe = selectedFolder.subscribe(async (folder) => {
|
||||||
await tick();
|
await tick();
|
||||||
// Folder default models apply to new chats only.
|
// Folder default models apply to new chats only.
|
||||||
if (
|
if (!history.currentId && folder) {
|
||||||
!history.currentId &&
|
const folderModels = normalizeSelectedModels(folder.data?.model_ids ?? []);
|
||||||
folder?.data?.model_ids &&
|
if (!equal(selectedModels, folderModels)) {
|
||||||
!equal(selectedModels, folder.data.model_ids)
|
selectedModels = folderModels;
|
||||||
) {
|
}
|
||||||
selectedModels = folder.data.model_ids;
|
|
||||||
|
|
||||||
console.log('Set selectedModels from folder data:', selectedModels);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -2162,9 +2140,9 @@
|
||||||
$models.map((m) => m.id).includes(modelId)
|
$models.map((m) => m.id).includes(modelId)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if ($selectedFolder?.data?.model_ids) {
|
if ($selectedFolder) {
|
||||||
// Set from folder model IDs
|
// Folder defaults are explicit; never inherit a previous chat's selection.
|
||||||
selectedModels = $selectedFolder?.data?.model_ids;
|
selectedModels = normalizeSelectedModels($selectedFolder.data?.model_ids ?? []);
|
||||||
} else {
|
} else {
|
||||||
if (sessionStorage.selectedModels) {
|
if (sessionStorage.selectedModels) {
|
||||||
// Set from session storage (temporary selection)
|
// Set from session storage (temporary selection)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext, createEventDispatcher, onMount, tick } from 'svelte';
|
import { getContext, createEventDispatcher, onMount, tick } from 'svelte';
|
||||||
|
import type { Writable } from 'svelte/store';
|
||||||
|
import type { i18n as I18n } from 'i18next';
|
||||||
|
|
||||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||||
import Modal from '$lib/components/common/Modal.svelte';
|
import Modal from '$lib/components/common/Modal.svelte';
|
||||||
|
|
@ -8,12 +10,13 @@
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { user, config } from '$lib/stores';
|
import { user, config, models } from '$lib/stores';
|
||||||
|
import { resolveLocalizedModelName } from '$lib/utils/localizedContent';
|
||||||
|
|
||||||
import Textarea from '$lib/components/common/Textarea.svelte';
|
import Textarea from '$lib/components/common/Textarea.svelte';
|
||||||
import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
|
import Knowledge from '$lib/components/workspace/Models/Knowledge.svelte';
|
||||||
import { getFolderById } from '$lib/apis/folders';
|
import { getFolderById } from '$lib/apis/folders';
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext<Writable<I18n>>('i18n');
|
||||||
|
|
||||||
export let show = false;
|
export let show = false;
|
||||||
export let onSubmit: Function = (e) => {};
|
export let onSubmit: Function = (e) => {};
|
||||||
|
|
@ -28,11 +31,13 @@
|
||||||
background_image_url: null
|
background_image_url: null
|
||||||
};
|
};
|
||||||
let data = {
|
let data = {
|
||||||
|
model_ids: null as string[] | null,
|
||||||
system_prompt: '',
|
system_prompt: '',
|
||||||
files: []
|
files: []
|
||||||
};
|
};
|
||||||
|
|
||||||
let loading = false;
|
let loading = false;
|
||||||
|
$: availableModels = $models.filter((model) => !(model?.info?.meta?.hidden ?? false));
|
||||||
|
|
||||||
const submitHandler = async () => {
|
const submitHandler = async () => {
|
||||||
loading = true;
|
loading = true;
|
||||||
|
|
@ -75,6 +80,7 @@
|
||||||
background_image_url: null
|
background_image_url: null
|
||||||
};
|
};
|
||||||
data = folder.data || {
|
data = folder.data || {
|
||||||
|
model_ids: null,
|
||||||
system_prompt: '',
|
system_prompt: '',
|
||||||
files: []
|
files: []
|
||||||
};
|
};
|
||||||
|
|
@ -102,6 +108,7 @@
|
||||||
background_image_url: null
|
background_image_url: null
|
||||||
};
|
};
|
||||||
data = {
|
data = {
|
||||||
|
model_ids: null,
|
||||||
system_prompt: '',
|
system_prompt: '',
|
||||||
files: []
|
files: []
|
||||||
};
|
};
|
||||||
|
|
@ -213,6 +220,33 @@
|
||||||
|
|
||||||
<hr class=" border-gray-50 dark:border-gray-850/30 my-2.5 w-full" />
|
<hr class=" border-gray-50 dark:border-gray-850/30 my-2.5 w-full" />
|
||||||
|
|
||||||
|
<div class="my-1">
|
||||||
|
<label for="folder-default-model" class="block mb-2 text-xs text-gray-500">
|
||||||
|
{$i18n.t('Default Model')}
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="folder-default-model"
|
||||||
|
class="w-full rounded-lg px-2 py-1.5 text-sm bg-gray-50 dark:bg-gray-850"
|
||||||
|
value={data.model_ids?.[0] ?? ''}
|
||||||
|
on:change={(event) => {
|
||||||
|
data.model_ids = event.currentTarget.value ? [event.currentTarget.value] : null;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<option value="">{$i18n.t('Use default')}</option>
|
||||||
|
{#if data.model_ids?.[0] && !availableModels.some((model) => model.id === data.model_ids?.[0])}
|
||||||
|
<option value={data.model_ids[0]} disabled>{data.model_ids[0]}</option>
|
||||||
|
{/if}
|
||||||
|
{#each availableModels as model (model.id)}
|
||||||
|
<option value={model.id}>{resolveLocalizedModelName(model, $i18n.language)}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
<p class="mt-1 text-xs text-gray-500">
|
||||||
|
{$i18n.t(
|
||||||
|
"Used for new chats in this folder. Changing a chat's model does not change this default."
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if $user?.role === 'admin' || ($user?.permissions.chat?.system_prompt ?? true)}
|
{#if $user?.role === 'admin' || ($user?.permissions.chat?.system_prompt ?? true)}
|
||||||
<div class="my-1">
|
<div class="my-1">
|
||||||
<div class="mb-2 text-xs text-gray-500">{$i18n.t('System Prompt')}</div>
|
<div class="mb-2 text-xs text-gray-500">{$i18n.t('System Prompt')}</div>
|
||||||
|
|
|
||||||
|
|
@ -3400,6 +3400,7 @@
|
||||||
"Use segmented retrieval for focused context.": "",
|
"Use segmented retrieval for focused context.": "",
|
||||||
"Use these in model system prompts as {{example}}.": "",
|
"Use these in model system prompts as {{example}}.": "",
|
||||||
"Use Web Search?": "",
|
"Use Web Search?": "",
|
||||||
|
"Used for new chats in this folder. Changing a chat's model does not change this default.": "",
|
||||||
"user": "",
|
"user": "",
|
||||||
"User": "",
|
"User": "",
|
||||||
"User Activity": "",
|
"User Activity": "",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue