Skip to content

Commit 90ca2e9

Browse files
committed
refac
1 parent 76ece40 commit 90ca2e9

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

backend/open_webui/models/models.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from open_webui.models.access_grants import AccessGrantModel, AccessGrants
1111

1212

13-
from pydantic import BaseModel, ConfigDict, Field
13+
from pydantic import BaseModel, ConfigDict, Field, model_validator
1414

1515
from sqlalchemy import String, cast, or_, and_, func
1616
from sqlalchemy.dialects import postgresql, sqlite
@@ -47,7 +47,20 @@ class ModelMeta(BaseModel):
4747

4848
model_config = ConfigDict(extra='allow')
4949

50-
pass
50+
@model_validator(mode='before')
51+
@classmethod
52+
def normalize_tags(cls, data):
53+
if isinstance(data, dict) and 'tags' in data:
54+
raw_tags = data['tags']
55+
if isinstance(raw_tags, list):
56+
normalized = []
57+
for tag in raw_tags:
58+
if isinstance(tag, str):
59+
normalized.append({'name': tag})
60+
elif isinstance(tag, dict) and 'name' in tag:
61+
normalized.append(tag)
62+
data['tags'] = normalized
63+
return data
5164

5265

5366
class Model(Base):

backend/open_webui/routers/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,14 @@ async def get_model_tags(user=Depends(get_verified_user), db: Session = Depends(
151151
if model.meta:
152152
meta = model.meta.model_dump()
153153
for tag in meta.get('tags', []):
154-
tags_set.add((tag.get('name')))
154+
try:
155+
name = tag.get('name') if isinstance(tag, dict) else str(tag)
156+
if name:
157+
tags_set.add(name)
158+
except Exception:
159+
continue
155160

156-
tags = [tag for tag in tags_set]
157-
tags.sort()
161+
tags = sorted(tags_set)
158162
return tags
159163

160164

0 commit comments

Comments
 (0)