forked from open-webui/open-webui
Merge pull request #357 from ollama-webui/global-default-models
feat: set default models globally
This commit is contained in:
commit
ae9ad35023
3 changed files with 36 additions and 28 deletions
|
@ -4,7 +4,7 @@ export const setDefaultModels = async (token: string, models: string) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/models`, {
|
const res = await fetch(`${WEBUI_API_BASE_URL}/configs/default/models`, {
|
||||||
method: 'GET',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
Authorization: `Bearer ${token}`
|
Authorization: `Bearer ${token}`
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { models, showSettings, settings } from '$lib/stores';
|
import { setDefaultModels } from '$lib/apis/configs';
|
||||||
|
import { models, showSettings, settings, user } from '$lib/stores';
|
||||||
import { onMount, tick } from 'svelte';
|
import { onMount, tick } from 'svelte';
|
||||||
import toast from 'svelte-french-toast';
|
import toast from 'svelte-french-toast';
|
||||||
|
|
||||||
export let selectedModels = [''];
|
export let selectedModels = [''];
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
|
|
||||||
const saveDefaultModel = () => {
|
const saveDefaultModel = async () => {
|
||||||
const hasEmptyModel = selectedModels.filter((it) => it === '');
|
const hasEmptyModel = selectedModels.filter((it) => it === '');
|
||||||
if (hasEmptyModel.length) {
|
if (hasEmptyModel.length) {
|
||||||
toast.error('Choose a model before saving...');
|
toast.error('Choose a model before saving...');
|
||||||
|
@ -14,6 +15,11 @@
|
||||||
}
|
}
|
||||||
settings.set({ ...$settings, models: selectedModels });
|
settings.set({ ...$settings, models: selectedModels });
|
||||||
localStorage.setItem('settings', JSON.stringify($settings));
|
localStorage.setItem('settings', JSON.stringify($settings));
|
||||||
|
|
||||||
|
if ($user.role === 'admin') {
|
||||||
|
console.log('setting default models globally');
|
||||||
|
await setDefaultModels(localStorage.token, selectedModels.join(','));
|
||||||
|
}
|
||||||
toast.success('Default model updated');
|
toast.success('Default model updated');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -761,6 +761,7 @@
|
||||||
<div class=" self-center">Advanced</div>
|
<div class=" self-center">Advanced</div>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{#if $user?.role === 'admin'}
|
||||||
<button
|
<button
|
||||||
class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
|
class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
|
||||||
'models'
|
'models'
|
||||||
|
@ -786,6 +787,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class=" self-center">Models</div>
|
<div class=" self-center">Models</div>
|
||||||
</button>
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
|
class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
|
||||||
|
|
Loading…
Reference in a new issue