mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 00:30:51 +00:00
refac
This commit is contained in:
parent
404875cab9
commit
e80e4c304a
@ -13,7 +13,7 @@ from constants import ERROR_MESSAGES
|
||||
router = APIRouter()
|
||||
|
||||
###########################
|
||||
# getAllModels
|
||||
# getModels
|
||||
###########################
|
||||
|
||||
|
||||
|
@ -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 () => {
|
||||
|
@ -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/`, {
|
||||
|
@ -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'));
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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'];
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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 = () => {
|
||||
|
@ -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 @@
|
||||
<div class="flex-1 md:min-h-[28rem]">
|
||||
{#if selectedTab === 'general'}
|
||||
<General
|
||||
{getAllModels}
|
||||
{getModels}
|
||||
{saveSettings}
|
||||
on:save={() => {
|
||||
toast.success($i18n.t('Settings saved successfully!'));
|
||||
}}
|
||||
/>
|
||||
{:else if selectedTab === 'models'}
|
||||
<Models {getAllModels} />
|
||||
<Models {getModels} />
|
||||
{:else if selectedTab === 'connections'}
|
||||
<Connections
|
||||
{getAllModels}
|
||||
{getModels}
|
||||
on:save={() => {
|
||||
toast.success($i18n.t('Settings saved successfully!'));
|
||||
}}
|
||||
|
@ -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]);
|
||||
|
@ -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
|
||||
//////////////////////////
|
||||
|
@ -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));
|
||||
|
@ -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 () => {
|
||||
|
@ -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 () => {
|
||||
|
Loading…
Reference in New Issue
Block a user