mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac
This commit is contained in:
parent
eb9c4c0e35
commit
6593b7ccc8
1 changed files with 44 additions and 31 deletions
|
|
@ -166,7 +166,8 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||||
action_ids = []
|
action_ids = []
|
||||||
filter_ids = []
|
filter_ids = []
|
||||||
|
|
||||||
if "info" in model and "meta" in model["info"]:
|
if "info" in model:
|
||||||
|
if "meta" in model["info"]:
|
||||||
action_ids.extend(
|
action_ids.extend(
|
||||||
model["info"]["meta"].get("actionIds", [])
|
model["info"]["meta"].get("actionIds", [])
|
||||||
)
|
)
|
||||||
|
|
@ -174,6 +175,10 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||||
model["info"]["meta"].get("filterIds", [])
|
model["info"]["meta"].get("filterIds", [])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "params" in model["info"]:
|
||||||
|
# Remove params to avoid exposing sensitive info
|
||||||
|
del model["info"]["params"]
|
||||||
|
|
||||||
model["action_ids"] = action_ids
|
model["action_ids"] = action_ids
|
||||||
model["filter_ids"] = filter_ids
|
model["filter_ids"] = filter_ids
|
||||||
else:
|
else:
|
||||||
|
|
@ -182,22 +187,40 @@ 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]
|
||||||
):
|
):
|
||||||
|
# Custom model based on a base model
|
||||||
owned_by = "openai"
|
owned_by = "openai"
|
||||||
pipe = None
|
pipe = None
|
||||||
|
|
||||||
|
for m in models:
|
||||||
|
if (
|
||||||
|
custom_model.base_model_id == m["id"]
|
||||||
|
or custom_model.base_model_id == m["id"].split(":")[0]
|
||||||
|
):
|
||||||
|
owned_by = m.get("owned_by", "unknown")
|
||||||
|
if "pipe" in m:
|
||||||
|
pipe = m["pipe"]
|
||||||
|
break
|
||||||
|
|
||||||
|
model = {
|
||||||
|
"id": f"{custom_model.id}",
|
||||||
|
"name": custom_model.name,
|
||||||
|
"object": "model",
|
||||||
|
"created": custom_model.created_at,
|
||||||
|
"owned_by": owned_by,
|
||||||
|
"preset": True,
|
||||||
|
**({"pipe": pipe} if pipe is not None else {}),
|
||||||
|
}
|
||||||
|
|
||||||
|
info = custom_model.model_dump()
|
||||||
|
if "params" in info:
|
||||||
|
# Remove params to avoid exposing sensitive info
|
||||||
|
del info["params"]
|
||||||
|
|
||||||
|
model["info"] = info
|
||||||
|
|
||||||
action_ids = []
|
action_ids = []
|
||||||
filter_ids = []
|
filter_ids = []
|
||||||
|
|
||||||
for model in models:
|
|
||||||
if (
|
|
||||||
custom_model.base_model_id == model["id"]
|
|
||||||
or custom_model.base_model_id == model["id"].split(":")[0]
|
|
||||||
):
|
|
||||||
owned_by = model.get("owned_by", "unknown owner")
|
|
||||||
if "pipe" in model:
|
|
||||||
pipe = model["pipe"]
|
|
||||||
break
|
|
||||||
|
|
||||||
if custom_model.meta:
|
if custom_model.meta:
|
||||||
meta = custom_model.meta.model_dump()
|
meta = custom_model.meta.model_dump()
|
||||||
|
|
||||||
|
|
@ -207,20 +230,10 @@ async def get_all_models(request, refresh: bool = False, user: UserModel = None)
|
||||||
if "filterIds" in meta:
|
if "filterIds" in meta:
|
||||||
filter_ids.extend(meta["filterIds"])
|
filter_ids.extend(meta["filterIds"])
|
||||||
|
|
||||||
models.append(
|
model["action_ids"] = action_ids
|
||||||
{
|
model["filter_ids"] = filter_ids
|
||||||
"id": f"{custom_model.id}",
|
|
||||||
"name": custom_model.name,
|
models.append(model)
|
||||||
"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):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue