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 @@