Update models.py

This commit is contained in:
Classic298 2025-08-11 23:36:48 +02:00 committed by GitHub
parent d8c4dd6f79
commit 357b57e1d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,7 +23,6 @@ from open_webui.utils.access_control import has_access
from open_webui.config import ( from open_webui.config import (
DEFAULT_ARENA_MODEL, DEFAULT_ARENA_MODEL,
ENABLE_ADMIN_WORKSPACE_CONTENT_ACCESS,
) )
from open_webui.env import SRC_LOG_LEVELS, GLOBAL_LOG_LEVEL from open_webui.env import SRC_LOG_LEVELS, GLOBAL_LOG_LEVEL
@ -182,62 +181,45 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
elif custom_model.is_active and ( elif custom_model.is_active and (
custom_model.id not in [model["id"] for model in models] custom_model.id not in [model["id"] for model in models]
): ):
# Check access control for custom models owned_by = "openai"
should_include = False pipe = None
if user and user.role == "admin" and ENABLE_ADMIN_WORKSPACE_CONTENT_ACCESS: action_ids = []
# Admin with full workspace access filter_ids = []
should_include = True
elif user and user.id == custom_model.user_id: for model in models:
# Owner always has access if (
should_include = True custom_model.base_model_id == model["id"]
elif user and has_access(user.id, "read", custom_model.access_control): or custom_model.base_model_id == model["id"].split(":")[0]
# User has explicit read access ):
should_include = True owned_by = model.get("owned_by", "unknown owner")
elif not user: if "pipe" in model:
# No user context - include for backwards compatibility pipe = model["pipe"]
should_include = True break
if should_include: if custom_model.meta:
owned_by = "openai" meta = custom_model.meta.model_dump()
pipe = None
if "actionIds" in meta:
action_ids = [] action_ids.extend(meta["actionIds"])
filter_ids = []
if "filterIds" in meta:
for model in models: filter_ids.extend(meta["filterIds"])
if (
custom_model.base_model_id == model["id"] models.append(
or custom_model.base_model_id == model["id"].split(":")[0] {
): "id": f"{custom_model.id}",
owned_by = model.get("owned_by", "unknown owner") "name": custom_model.name,
if "pipe" in model: "object": "model",
pipe = model["pipe"] "created": custom_model.created_at,
break "owned_by": owned_by,
"info": custom_model.model_dump(),
if custom_model.meta: "preset": True,
meta = custom_model.meta.model_dump() **({"pipe": pipe} if pipe is not None else {}),
"action_ids": action_ids,
if "actionIds" in meta: "filter_ids": filter_ids,
action_ids.extend(meta["actionIds"]) }
)
if "filterIds" in meta:
filter_ids.extend(meta["filterIds"])
models.append(
{
"id": f"{custom_model.id}",
"name": custom_model.name,
"object": "model",
"created": custom_model.created_at,
"owned_by": owned_by,
"info": custom_model.model_dump(),
"preset": True,
**({"pipe": pipe} if pipe is not None else {}),
"action_ids": action_ids,
"filter_ids": filter_ids,
}
)
# Process action_ids to get the actions # Process action_ids to get the actions
def get_action_items_from_module(function, module): def get_action_items_from_module(function, module):