diff --git a/backend/apps/web/routers/models.py b/backend/apps/web/routers/models.py index 696e359d9..8b9b380b4 100644 --- a/backend/apps/web/routers/models.py +++ b/backend/apps/web/routers/models.py @@ -13,7 +13,7 @@ from constants import ERROR_MESSAGES router = APIRouter() ########################### -# getAllModels +# getModels ########################### diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 9d776ff7e..a96dbfaf4 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -25,7 +25,12 @@ export const getModels = async (token: string = '') => { 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 () => { diff --git a/src/lib/apis/models/index.ts b/src/lib/apis/models/index.ts index 56c299fb2..092926583 100644 --- a/src/lib/apis/models/index.ts +++ b/src/lib/apis/models/index.ts @@ -29,7 +29,7 @@ export const addNewModel = async (token: string, model: object) => { return res; }; -export const getModels = async (token: string = '') => { +export const getModelInfos = async (token: string = '') => { let error = null; const res = await fetch(`${WEBUI_API_BASE_URL}/models/`, { diff --git a/src/lib/components/chat/ModelSelector/Selector.svelte b/src/lib/components/chat/ModelSelector/Selector.svelte index e72eb7e10..40e0bac6c 100644 --- a/src/lib/components/chat/ModelSelector/Selector.svelte +++ b/src/lib/components/chat/ModelSelector/Selector.svelte @@ -12,12 +12,9 @@ import { user, MODEL_DOWNLOAD_POOL, models, mobile } from '$lib/stores'; import { toast } from 'svelte-sonner'; - import { - capitalizeFirstLetter, - getAllModels, - sanitizeResponseContent, - splitStream - } from '$lib/utils'; + import { capitalizeFirstLetter, sanitizeResponseContent, splitStream } from '$lib/utils'; + import { getModels } from '$lib/apis'; + import Tooltip from '$lib/components/common/Tooltip.svelte'; const i18n = getContext('i18n'); @@ -159,7 +156,7 @@ }) ); - models.set(await getAllModels(localStorage.token)); + models.set(await getModels(localStorage.token)); } else { toast.error($i18n.t('Download canceled')); } diff --git a/src/lib/components/chat/Settings/Connections.svelte b/src/lib/components/chat/Settings/Connections.svelte index f928e0f44..b9978e129 100644 --- a/src/lib/components/chat/Settings/Connections.svelte +++ b/src/lib/components/chat/Settings/Connections.svelte @@ -23,7 +23,7 @@ const i18n = getContext('i18n'); - export let getAllModels: Function; + export let getModels: Function; // External let OLLAMA_BASE_URLS = ['']; @@ -38,7 +38,7 @@ OPENAI_API_BASE_URLS = await updateOpenAIUrls(localStorage.token, OPENAI_API_BASE_URLS); OPENAI_API_KEYS = await updateOpenAIKeys(localStorage.token, OPENAI_API_KEYS); - await models.set(await getAllModels()); + await models.set(await getModels()); }; const updateOllamaUrlsHandler = async () => { @@ -51,7 +51,7 @@ if (ollamaVersion) { toast.success($i18n.t('Server connection verified')); - await models.set(await getAllModels()); + await models.set(await getModels()); } }; diff --git a/src/lib/components/chat/Settings/General.svelte b/src/lib/components/chat/Settings/General.svelte index 060eb8b20..a30cc1896 100644 --- a/src/lib/components/chat/Settings/General.svelte +++ b/src/lib/components/chat/Settings/General.svelte @@ -11,7 +11,7 @@ import AdvancedParams from './Advanced/AdvancedParams.svelte'; export let saveSettings: Function; - export let getAllModels: Function; + export let getModels: Function; // General let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light', 'oled-dark']; diff --git a/src/lib/components/chat/Settings/Images.svelte b/src/lib/components/chat/Settings/Images.svelte index ff117f6ae..19e050ca8 100644 --- a/src/lib/components/chat/Settings/Images.svelte +++ b/src/lib/components/chat/Settings/Images.svelte @@ -42,7 +42,7 @@ let imageSize = ''; let steps = 50; - const getAllModels = async () => { + const getModels = async () => { models = await getImageGenerationModels(localStorage.token).catch((error) => { toast.error(error); return null; @@ -66,7 +66,7 @@ if (res) { COMFYUI_BASE_URL = res.COMFYUI_BASE_URL; - await getAllModels(); + await getModels(); if (models) { toast.success($i18n.t('Server connection verified')); @@ -85,7 +85,7 @@ if (res) { AUTOMATIC1111_BASE_URL = res.AUTOMATIC1111_BASE_URL; - await getAllModels(); + await getModels(); if (models) { toast.success($i18n.t('Server connection verified')); @@ -112,7 +112,7 @@ if (enableImageGeneration) { config.set(await getBackendConfig(localStorage.token)); - getAllModels(); + getModels(); } }; @@ -141,7 +141,7 @@ steps = await getImageSteps(localStorage.token); if (enableImageGeneration) { - getAllModels(); + getModels(); } } }); diff --git a/src/lib/components/chat/Settings/Models.svelte b/src/lib/components/chat/Settings/Models.svelte index 8f5cce76f..941408872 100644 --- a/src/lib/components/chat/Settings/Models.svelte +++ b/src/lib/components/chat/Settings/Models.svelte @@ -22,7 +22,7 @@ const i18n = getContext('i18n'); - export let getAllModels: Function; + export let getModels: Function; let showLiteLLM = false; let showLiteLLMParams = false; @@ -261,7 +261,7 @@ }) ); - models.set(await getAllModels(localStorage.token)); + models.set(await getModels(localStorage.token)); } else { toast.error($i18n.t('Download canceled')); } @@ -424,7 +424,7 @@ modelTransferring = false; uploadProgress = null; - models.set(await getAllModels()); + models.set(await getModels()); }; const deleteModelHandler = async () => { @@ -439,7 +439,7 @@ } deleteModelTag = ''; - models.set(await getAllModels()); + models.set(await getModels()); }; const cancelModelPullHandler = async (model: string) => { @@ -488,7 +488,7 @@ liteLLMMaxTokens = ''; liteLLMModelInfo = await getLiteLLMModelInfo(localStorage.token); - models.set(await getAllModels()); + models.set(await getModels()); }; const deleteLiteLLMModelHandler = async () => { @@ -507,7 +507,7 @@ deleteLiteLLMModelName = ''; liteLLMModelInfo = await getLiteLLMModelInfo(localStorage.token); - models.set(await getAllModels()); + models.set(await getModels()); }; const addModelInfoHandler = async () => { @@ -534,7 +534,7 @@ toast.success( $i18n.t('Model info for {{modelName}} added successfully', { modelName: selectedModelId }) ); - models.set(await getAllModels()); + models.set(await getModels()); }; const deleteModelInfoHandler = async () => { @@ -550,7 +550,7 @@ toast.success( $i18n.t('Model info for {{modelName}} deleted successfully', { modelName: selectedModelId }) ); - models.set(await getAllModels()); + models.set(await getModels()); }; const toggleIsVisionCapable = () => { diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index e2782441c..fd7cea574 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -3,7 +3,7 @@ import { toast } from 'svelte-sonner'; 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 Account from './Settings/Account.svelte'; @@ -25,12 +25,12 @@ const saveSettings = async (updated) => { console.log(updated); await settings.set({ ...$settings, ...updated }); - await models.set(await getAllModels()); + await models.set(await getModels()); localStorage.setItem('settings', JSON.stringify($settings)); }; - const getAllModels = async () => { - return await _getAllModels(localStorage.token); + const getModels = async () => { + return await _getModels(localStorage.token); }; let selectedTab = 'general'; @@ -318,17 +318,17 @@
{#if selectedTab === 'general'} { toast.success($i18n.t('Settings saved successfully!')); }} /> {:else if selectedTab === 'models'} - + {:else if selectedTab === 'connections'} { toast.success($i18n.t('Settings saved successfully!')); }} diff --git a/src/lib/components/workspace/Models.svelte b/src/lib/components/workspace/Models.svelte index 9d0145e96..daa2f79d7 100644 --- a/src/lib/components/workspace/Models.svelte +++ b/src/lib/components/workspace/Models.svelte @@ -6,9 +6,10 @@ import { onMount, getContext } from 'svelte'; 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 { getAllModels } from '$lib/utils'; + + import { getModels } from '$lib/apis'; const i18n = getContext('i18n'); @@ -22,7 +23,7 @@ if (res) { 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) => { @@ -236,7 +237,7 @@ }); } - await modelfiles.set(await getModels(localStorage.token)); + await modelfiles.set(await getModelInfos(localStorage.token)); }; reader.readAsText(importFiles[0]); diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index e362634c3..a258b35b0 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -1,20 +1,6 @@ import { v4 as uuidv4 } from 'uuid'; 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 ////////////////////////// diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index a4dd0ae06..0aa9ce683 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -7,7 +7,7 @@ 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 { getPrompts } from '$lib/apis/prompts'; @@ -45,8 +45,8 @@ let showShortcuts = false; - const getAllModels = async () => { - return _getAllModels(localStorage.token); + const getModels = async () => { + return _getModels(localStorage.token); }; onMount(async () => { @@ -75,7 +75,7 @@ await Promise.all([ (async () => { - models.set(await getAllModels()); + models.set(await getModels()); })(), (async () => { prompts.set(await getPrompts(localStorage.token)); diff --git a/src/routes/(app)/workspace/models/create/+page.svelte b/src/routes/(app)/workspace/models/create/+page.svelte index 8ed15bbd8..092b9fc55 100644 --- a/src/routes/(app)/workspace/models/create/+page.svelte +++ b/src/routes/(app)/workspace/models/create/+page.svelte @@ -8,7 +8,7 @@ import { splitStream } from '$lib/utils'; import { onMount, tick, getContext } from 'svelte'; 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'); @@ -99,7 +99,7 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, ''); const saveModelfile = async (modelfile) => { await addNewModel(localStorage.token, modelfile); - await modelfiles.set(await getModels(localStorage.token)); + await modelfiles.set(await getModelInfos(localStorage.token)); }; const submitHandler = async () => { diff --git a/src/routes/(app)/workspace/models/edit/+page.svelte b/src/routes/(app)/workspace/models/edit/+page.svelte index 7390e91ea..a8e22901a 100644 --- a/src/routes/(app)/workspace/models/edit/+page.svelte +++ b/src/routes/(app)/workspace/models/edit/+page.svelte @@ -10,7 +10,7 @@ import { splitStream } from '$lib/utils'; 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'; @@ -86,7 +86,7 @@ const updateModelfile = async (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 () => {