"docs/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "e5b4bf1a93fa0bbcfb2cd4c88ac292c2221e74b7"
Commit dfde45d3 authored by Timothy J. Baek's avatar Timothy J. Baek
Browse files

feat: set default models globally

parent 5719bcad
...@@ -4,7 +4,7 @@ export const setDefaultModels = async (token: string, models: string) => { ...@@ -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}`
......
<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 @@ ...@@ -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('admin');
await setDefaultModels(localStorage.token, selectedModels.join(','));
}
toast.success('Default model updated'); toast.success('Default model updated');
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment