This commit is contained in:
Timothy J. Baek 2024-05-24 02:17:48 -07:00
parent 404875cab9
commit e80e4c304a
14 changed files with 49 additions and 60 deletions

View File

@ -13,7 +13,7 @@ from constants import ERROR_MESSAGES
router = APIRouter() router = APIRouter()
########################### ###########################
# getAllModels # getModels
########################### ###########################

View File

@ -25,7 +25,12 @@ export const getModels = async (token: string = '') => {
throw error; throw error;
} }
return res?.data ?? []; let models = res?.data ?? [];
models = models.filter((models) => models).reduce((a, e, i, arr) => a.concat(e), []);
console.log(models);
return models;
}; };
export const getBackendConfig = async () => { export const getBackendConfig = async () => {

View File

@ -29,7 +29,7 @@ export const addNewModel = async (token: string, model: object) => {
return res; return res;
}; };
export const getModels = async (token: string = '') => { export const getModelInfos = async (token: string = '') => {
let error = null; let error = null;
const res = await fetch(`${WEBUI_API_BASE_URL}/models/`, { const res = await fetch(`${WEBUI_API_BASE_URL}/models/`, {

View File

@ -12,12 +12,9 @@
import { user, MODEL_DOWNLOAD_POOL, models, mobile } from '$lib/stores'; import { user, MODEL_DOWNLOAD_POOL, models, mobile } from '$lib/stores';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { import { capitalizeFirstLetter, sanitizeResponseContent, splitStream } from '$lib/utils';
capitalizeFirstLetter, import { getModels } from '$lib/apis';
getAllModels,
sanitizeResponseContent,
splitStream
} from '$lib/utils';
import Tooltip from '$lib/components/common/Tooltip.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -159,7 +156,7 @@
}) })
); );
models.set(await getAllModels(localStorage.token)); models.set(await getModels(localStorage.token));
} else { } else {
toast.error($i18n.t('Download canceled')); toast.error($i18n.t('Download canceled'));
} }

View File

@ -23,7 +23,7 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let getAllModels: Function; export let getModels: Function;
// External // External
let OLLAMA_BASE_URLS = ['']; let OLLAMA_BASE_URLS = [''];
@ -38,7 +38,7 @@
OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS); OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS);
OPENAI_API_KEYS = await updateOpenAIKeys(localStorage.token, OPENAI_API_KEYS); OPENAI_API_KEYS = await updateOpenAIKeys(localStorage.token, OPENAI_API_KEYS);
await models.set(await getAllModels()); await models.set(await getModels());
}; };
const updateOllamaUrlsHandler = async () => { const updateOllamaUrlsHandler = async () => {
@ -51,7 +51,7 @@
if (ollamaVersion) { if (ollamaVersion) {
toast.success($i18n.t('Server connection verified')); toast.success($i18n.t('Server connection verified'));
await models.set(await getAllModels()); await models.set(await getModels());
} }
}; };

View File

@ -11,7 +11,7 @@
import AdvancedParams from './Advanced/AdvancedParams.svelte'; import AdvancedParams from './Advanced/AdvancedParams.svelte';
export let saveSettings: Function; export let saveSettings: Function;
export let getAllModels: Function; export let getModels: Function;
// General // General
let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light', 'oled-dark']; let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light', 'oled-dark'];

View File

@ -42,7 +42,7 @@
let imageSize = ''; let imageSize = '';
let steps = 50; let steps = 50;
const getAllModels = async () => { const getModels = async () => {
models = await getImageGenerationModels(localStorage.token).catch((error) => { models = await getImageGenerationModels(localStorage.token).catch((error) => {
toast.error(error); toast.error(error);
return null; return null;
@ -66,7 +66,7 @@
if (res) { if (res) {
COMFYUI_BASE_URL = res.COMFYUI_BASE_URL; COMFYUI_BASE_URL = res.COMFYUI_BASE_URL;
await getAllModels(); await getModels();
if (models) { if (models) {
toast.success($i18n.t('Server connection verified')); toast.success($i18n.t('Server connection verified'));
@ -85,7 +85,7 @@
if (res) { if (res) {
AUTOMATIC1111_BASE_URL = res.AUTOMATIC1111_BASE_URL; AUTOMATIC1111_BASE_URL = res.AUTOMATIC1111_BASE_URL;
await getAllModels(); await getModels();
if (models) { if (models) {
toast.success($i18n.t('Server connection verified')); toast.success($i18n.t('Server connection verified'));
@ -112,7 +112,7 @@
if (enableImageGeneration) { if (enableImageGeneration) {
config.set(await getBackendConfig(localStorage.token)); config.set(await getBackendConfig(localStorage.token));
getAllModels(); getModels();
} }
}; };
@ -141,7 +141,7 @@
steps = await getImageSteps(localStorage.token); steps = await getImageSteps(localStorage.token);
if (enableImageGeneration) { if (enableImageGeneration) {
getAllModels(); getModels();
} }
} }
}); });

View File

@ -22,7 +22,7 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let getAllModels: Function; export let getModels: Function;
let showLiteLLM = false; let showLiteLLM = false;
let showLiteLLMParams = false; let showLiteLLMParams = false;
@ -261,7 +261,7 @@
}) })
); );
models.set(await getAllModels(localStorage.token)); models.set(await getModels(localStorage.token));
} else { } else {
toast.error($i18n.t('Download canceled')); toast.error($i18n.t('Download canceled'));
} }
@ -424,7 +424,7 @@
modelTransferring = false; modelTransferring = false;
uploadProgress = null; uploadProgress = null;
models.set(await getAllModels()); models.set(await getModels());
}; };
const deleteModelHandler = async () => { const deleteModelHandler = async () => {
@ -439,7 +439,7 @@
} }
deleteModelTag = ''; deleteModelTag = '';
models.set(await getAllModels()); models.set(await getModels());
}; };
const cancelModelPullHandler = async (model: string) => { const cancelModelPullHandler = async (model: string) => {
@ -488,7 +488,7 @@
liteLLMMaxTokens = ''; liteLLMMaxTokens = '';
liteLLMModelInfo = await getLiteLLMModelInfo(localStorage.token); liteLLMModelInfo = await getLiteLLMModelInfo(localStorage.token);
models.set(await getAllModels()); models.set(await getModels());
}; };
const deleteLiteLLMModelHandler = async () => { const deleteLiteLLMModelHandler = async () => {
@ -507,7 +507,7 @@
deleteLiteLLMModelName = ''; deleteLiteLLMModelName = '';
liteLLMModelInfo = await getLiteLLMModelInfo(localStorage.token); liteLLMModelInfo = await getLiteLLMModelInfo(localStorage.token);
models.set(await getAllModels()); models.set(await getModels());
}; };
const addModelInfoHandler = async () => { const addModelInfoHandler = async () => {
@ -534,7 +534,7 @@
toast.success( toast.success(
$i18n.t('Model info for {{modelName}} added successfully', { modelName: selectedModelId }) $i18n.t('Model info for {{modelName}} added successfully', { modelName: selectedModelId })
); );
models.set(await getAllModels()); models.set(await getModels());
}; };
const deleteModelInfoHandler = async () => { const deleteModelInfoHandler = async () => {
@ -550,7 +550,7 @@
toast.success( toast.success(
$i18n.t('Model info for {{modelName}} deleted successfully', { modelName: selectedModelId }) $i18n.t('Model info for {{modelName}} deleted successfully', { modelName: selectedModelId })
); );
models.set(await getAllModels()); models.set(await getModels());
}; };
const toggleIsVisionCapable = () => { const toggleIsVisionCapable = () => {

View File

@ -3,7 +3,7 @@
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { models, settings, user } from '$lib/stores'; import { models, settings, user } from '$lib/stores';
import { getAllModels as _getAllModels } from '$lib/utils'; import { getModels as _getModels } from '$lib/apis';
import Modal from '../common/Modal.svelte'; import Modal from '../common/Modal.svelte';
import Account from './Settings/Account.svelte'; import Account from './Settings/Account.svelte';
@ -25,12 +25,12 @@
const saveSettings = async (updated) => { const saveSettings = async (updated) => {
console.log(updated); console.log(updated);
await settings.set({ ...$settings, ...updated }); await settings.set({ ...$settings, ...updated });
await models.set(await getAllModels()); await models.set(await getModels());
localStorage.setItem('settings', JSON.stringify($settings)); localStorage.setItem('settings', JSON.stringify($settings));
}; };
const getAllModels = async () => { const getModels = async () => {
return await _getAllModels(localStorage.token); return await _getModels(localStorage.token);
}; };
let selectedTab = 'general'; let selectedTab = 'general';
@ -318,17 +318,17 @@
<div class="flex-1 md:min-h-[28rem]"> <div class="flex-1 md:min-h-[28rem]">
{#if selectedTab === 'general'} {#if selectedTab === 'general'}
<General <General
{getAllModels} {getModels}
{saveSettings} {saveSettings}
on:save={() => { on:save={() => {
toast.success($i18n.t('Settings saved successfully!')); toast.success($i18n.t('Settings saved successfully!'));
}} }}
/> />
{:else if selectedTab === 'models'} {:else if selectedTab === 'models'}
<Models {getAllModels} /> <Models {getModels} />
{:else if selectedTab === 'connections'} {:else if selectedTab === 'connections'}
<Connections <Connections
{getAllModels} {getModels}
on:save={() => { on:save={() => {
toast.success($i18n.t('Settings saved successfully!')); toast.success($i18n.t('Settings saved successfully!'));
}} }}

View File

@ -6,9 +6,10 @@
import { onMount, getContext } from 'svelte'; import { onMount, getContext } from 'svelte';
import { WEBUI_NAME, modelfiles, models, settings, user } from '$lib/stores'; import { WEBUI_NAME, modelfiles, models, settings, user } from '$lib/stores';
import { addNewModel, deleteModelById, getModels } from '$lib/apis/models'; import { addNewModel, deleteModelById, getModelInfos } from '$lib/apis/models';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { getAllModels } from '$lib/utils';
import { getModels } from '$lib/apis';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -22,7 +23,7 @@
if (res) { if (res) {
toast.success($i18n.t(`Deleted {{tagName}}`, { id })); toast.success($i18n.t(`Deleted {{tagName}}`, { id }));
} }
await models.set(await getAllModels(localStorage.token)); await models.set(await getModels(localStorage.token));
}; };
const shareModelHandler = async (model) => { const shareModelHandler = async (model) => {
@ -236,7 +237,7 @@
}); });
} }
await modelfiles.set(await getModels(localStorage.token)); await modelfiles.set(await getModelInfos(localStorage.token));
}; };
reader.readAsText(importFiles[0]); reader.readAsText(importFiles[0]);

View File

@ -1,20 +1,6 @@
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import sha256 from 'js-sha256'; import sha256 from 'js-sha256';
import { getModels } from '$lib/apis';
export const getAllModels = async (token: string) => {
let models = await getModels(token).catch((error) => {
console.log(error);
return null;
});
models = models.filter((models) => models).reduce((a, e, i, arr) => a.concat(e), []);
console.log(models);
return models;
};
////////////////////////// //////////////////////////
// Helper functions // Helper functions
////////////////////////// //////////////////////////

View File

@ -7,7 +7,7 @@
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { getAllModels as _getAllModels } from '$lib/utils'; import { getModels as _getModels } from '$lib/apis';
import { getOllamaVersion } from '$lib/apis/ollama'; import { getOllamaVersion } from '$lib/apis/ollama';
import { getPrompts } from '$lib/apis/prompts'; import { getPrompts } from '$lib/apis/prompts';
@ -45,8 +45,8 @@
let showShortcuts = false; let showShortcuts = false;
const getAllModels = async () => { const getModels = async () => {
return _getAllModels(localStorage.token); return _getModels(localStorage.token);
}; };
onMount(async () => { onMount(async () => {
@ -75,7 +75,7 @@
await Promise.all([ await Promise.all([
(async () => { (async () => {
models.set(await getAllModels()); models.set(await getModels());
})(), })(),
(async () => { (async () => {
prompts.set(await getPrompts(localStorage.token)); prompts.set(await getPrompts(localStorage.token));

View File

@ -8,7 +8,7 @@
import { splitStream } from '$lib/utils'; import { splitStream } from '$lib/utils';
import { onMount, tick, getContext } from 'svelte'; import { onMount, tick, getContext } from 'svelte';
import { createModel } from '$lib/apis/ollama'; import { createModel } from '$lib/apis/ollama';
import { addNewModel, getModelById, getModels } from '$lib/apis/models'; import { addNewModel, getModelById, getModelInfos } from '$lib/apis/models';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -99,7 +99,7 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, '');
const saveModelfile = async (modelfile) => { const saveModelfile = async (modelfile) => {
await addNewModel(localStorage.token, modelfile); await addNewModel(localStorage.token, modelfile);
await modelfiles.set(await getModels(localStorage.token)); await modelfiles.set(await getModelInfos(localStorage.token));
}; };
const submitHandler = async () => { const submitHandler = async () => {

View File

@ -10,7 +10,7 @@
import { splitStream } from '$lib/utils'; import { splitStream } from '$lib/utils';
import { createModel } from '$lib/apis/ollama'; import { createModel } from '$lib/apis/ollama';
import { getModels, updateModelById } from '$lib/apis/models'; import { getModelInfos, updateModelById } from '$lib/apis/models';
import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte'; import AdvancedParams from '$lib/components/chat/Settings/Advanced/AdvancedParams.svelte';
@ -86,7 +86,7 @@
const updateModelfile = async (modelfile) => { const updateModelfile = async (modelfile) => {
await updateModelById(localStorage.token, modelfile.tagName, modelfile); await updateModelById(localStorage.token, modelfile.tagName, modelfile);
await modelfiles.set(await getModels(localStorage.token)); await modelfiles.set(await getModelInfos(localStorage.token));
}; };
const updateHandler = async () => { const updateHandler = async () => {