mirror of
https://github.com/open-webui/open-webui.git
synced 2026-01-01 22:25:20 +00:00
enh: models endpoint optimization
Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com> #20010
This commit is contained in:
parent
53c1ca64b7
commit
0dd2cfe1f2
2 changed files with 15 additions and 1 deletions
|
|
@ -357,6 +357,14 @@ class ModelsTable:
|
|||
except Exception:
|
||||
return None
|
||||
|
||||
def get_models_by_ids(self, ids: list[str]) -> list[ModelModel]:
|
||||
try:
|
||||
with get_db() as db:
|
||||
models = db.query(Model).filter(Model.id.in_(ids)).all()
|
||||
return [ModelModel.model_validate(model) for model in models]
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
def toggle_model_by_id(self, id: str) -> Optional[ModelModel]:
|
||||
with get_db() as db:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -366,6 +366,12 @@ def get_filtered_models(models, user):
|
|||
user.role == "user"
|
||||
or (user.role == "admin" and not BYPASS_ADMIN_ACCESS_CONTROL)
|
||||
) and not BYPASS_MODEL_ACCESS_CONTROL:
|
||||
model_ids = [model["id"] for model in models if not model.get("arena")]
|
||||
model_infos = {
|
||||
model_info.id: model_info
|
||||
for model_info in Models.get_models_by_ids(model_ids)
|
||||
}
|
||||
|
||||
filtered_models = []
|
||||
user_group_ids = {group.id for group in Groups.get_groups_by_member_id(user.id)}
|
||||
for model in models:
|
||||
|
|
@ -381,7 +387,7 @@ def get_filtered_models(models, user):
|
|||
filtered_models.append(model)
|
||||
continue
|
||||
|
||||
model_info = Models.get_model_by_id(model["id"])
|
||||
model_info = model_infos.get(model["id"], None)
|
||||
if model_info:
|
||||
if (
|
||||
(user.role == "admin" and BYPASS_ADMIN_ACCESS_CONTROL)
|
||||
|
|
|
|||
Loading…
Reference in a new issue