refac
This commit is contained in:
@@ -10,7 +10,7 @@ from open_webui.models.users import User, UserModel, Users, UserResponse
|
|||||||
from open_webui.models.access_grants import AccessGrantModel, AccessGrants
|
from open_webui.models.access_grants import AccessGrantModel, AccessGrants
|
||||||
|
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||||
|
|
||||||
from sqlalchemy import String, cast, or_, and_, func
|
from sqlalchemy import String, cast, or_, and_, func
|
||||||
from sqlalchemy.dialects import postgresql, sqlite
|
from sqlalchemy.dialects import postgresql, sqlite
|
||||||
@@ -47,7 +47,20 @@ class ModelMeta(BaseModel):
|
|||||||
|
|
||||||
model_config = ConfigDict(extra='allow')
|
model_config = ConfigDict(extra='allow')
|
||||||
|
|
||||||
pass
|
@model_validator(mode='before')
|
||||||
|
@classmethod
|
||||||
|
def normalize_tags(cls, data):
|
||||||
|
if isinstance(data, dict) and 'tags' in data:
|
||||||
|
raw_tags = data['tags']
|
||||||
|
if isinstance(raw_tags, list):
|
||||||
|
normalized = []
|
||||||
|
for tag in raw_tags:
|
||||||
|
if isinstance(tag, str):
|
||||||
|
normalized.append({'name': tag})
|
||||||
|
elif isinstance(tag, dict) and 'name' in tag:
|
||||||
|
normalized.append(tag)
|
||||||
|
data['tags'] = normalized
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class Model(Base):
|
class Model(Base):
|
||||||
|
|||||||
@@ -151,10 +151,14 @@ async def get_model_tags(user=Depends(get_verified_user), db: Session = Depends(
|
|||||||
if model.meta:
|
if model.meta:
|
||||||
meta = model.meta.model_dump()
|
meta = model.meta.model_dump()
|
||||||
for tag in meta.get('tags', []):
|
for tag in meta.get('tags', []):
|
||||||
tags_set.add((tag.get('name')))
|
try:
|
||||||
|
name = tag.get('name') if isinstance(tag, dict) else str(tag)
|
||||||
|
if name:
|
||||||
|
tags_set.add(name)
|
||||||
|
except Exception:
|
||||||
|
continue
|
||||||
|
|
||||||
tags = [tag for tag in tags_set]
|
tags = sorted(tags_set)
|
||||||
tags.sort()
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user