This commit is contained in:
Timothy Jaeryang Baek 2026-09-12 18:16:19 -04:00
parent afda094544
commit 199490eadb
3 changed files with 34 additions and 14 deletions

View file

@ -215,6 +215,11 @@ async def get_models(
###########################
@router.get('/all', response_model=list[ModelResponse])
async def get_all_model_records(user=Depends(get_admin_user), db: AsyncSession = Depends(get_async_session)):
return await Models.get_all_models(db=db)
@router.get('/base/tags', response_model=list[str])
async def get_base_model_tags(user=Depends(get_admin_user), db: AsyncSession = Depends(get_async_session)):
tags = await Models.get_all_tags(user_id=user.id, is_admin=True, is_base_model=True, db=db)

View file

@ -149,6 +149,18 @@ export const importModels = async (token: string, models: object[]) => {
return res;
};
export const getAllModels = async (token: string = '') => {
const res = await fetch(`${WEBUI_API_BASE_URL}/models/all`, {
method: 'GET',
headers: {
Accept: 'application/json',
authorization: `Bearer ${token}`
}
});
if (!res.ok) throw await res.json();
return res.json();
};
export const getBaseModels = async (token: string = '', tag: string = '') => {
let error = null;

View file

@ -18,8 +18,7 @@
import {
createNewModel,
deleteAllModels,
getBaseModelTags,
getBaseModels,
getAllModels,
getModelById,
toggleModelById,
updateModelById,
@ -88,7 +87,7 @@
let defaultModelIdSet = new Set<string>();
let defaultPinnedModelIdSet = new Set<string>();
let baseModels: ModelListItem[] = [];
let savedModels: ModelListItem[] = [];
let allModels: ModelListItem[] = [];
let filteredModels = [];
@ -121,6 +120,10 @@
const isPresetModel = (model: any) =>
!!(model?.preset || model?.base_model_id || model?.info?.base_model_id);
const modelTags = (model: any): string[] =>
(model?.meta?.tags ?? [])
.map((tag) => (typeof tag === 'string' ? tag : tag?.name))
.filter(Boolean);
const modelAccessLabel = (model) => {
if (isPublicModel(model)) {
@ -264,12 +267,12 @@
.split(',')
.filter((id) => id);
tags = await getBaseModelTags(localStorage.token);
savedModels = await getAllModels(localStorage.token);
tags = [...new Set(savedModels.flatMap(modelTags))].sort();
if (selectedTag && !tags.includes(selectedTag)) {
selectedTag = '';
}
baseModels = await getBaseModels(localStorage.token, selectedTag);
allModels = await getModels(localStorage.token);
const providerModels = await getModels(localStorage.token, null, true);
@ -278,18 +281,17 @@
...allModels,
...providerModels.filter((model: ModelListItem) => !allModelIds.has(model.id))
];
const baseModelIds = new Set<string>(baseModels.map((model: ModelListItem) => model.id));
const listedModelIds = new Set(allModels.map((model) => model.id));
allModels.push(...savedModels.filter((model) => !listedModelIds.has(model.id)));
models = allModels
.filter((m: ModelListItem) => !selectedTag || baseModelIds.has(m.id))
.map((m: ModelListItem) => {
const baseModel = baseModels.find((model: ModelListItem) => model.id === m.id);
const savedModel = savedModels.find((model: ModelListItem) => model.id === m.id);
if (baseModel) {
if (savedModel) {
return {
...m,
...baseModel
...savedModel
};
} else {
return {
@ -300,7 +302,8 @@
is_active: true
};
}
});
})
.filter((model) => !selectedTag || modelTags(model).includes(selectedTag));
modelOrderList = [
...modelOrderList.filter((id) => models.some((model) => model.id === id)),
@ -470,7 +473,7 @@
const upsertModelHandler = async (model, overrides = {}, showToast = true) => {
model = { ...model, ...(isPresetModel(model) ? {} : { base_model_id: null }), ...overrides };
if (baseModels.find((m: ModelListItem) => m.id === model.id) || isPresetModel(model)) {
if (savedModels.find((m: ModelListItem) => m.id === model.id) || isPresetModel(model)) {
const res = await updateModelById(localStorage.token, model.id, model).catch((error) => {
return null;
});
@ -602,7 +605,7 @@
};
const getFullModel = async (model: any) =>
baseModels.some((baseModel) => baseModel.id === model.id) || isPresetModel(model)
savedModels.some((savedModel) => savedModel.id === model.id) || isPresetModel(model)
? ((await getModelById(localStorage.token, model.id).catch(() => null)) ?? model)
: model;