enh: models display author name

This commit is contained in:
Timothy Jaeryang Baek 2024-11-18 05:37:04 -08:00
parent 03b606925e
commit a2a25fb571
5 changed files with 33 additions and 20 deletions

View File

@ -1,3 +1,5 @@
# TODO: move socket to webui app
import asyncio
import socketio
import logging

View File

@ -5,7 +5,7 @@ from typing import Optional
from open_webui.apps.webui.internal.db import Base, JSONField, get_db
from open_webui.env import SRC_LOG_LEVELS
from open_webui.apps.webui.models.groups import Groups
from open_webui.apps.webui.models.users import Users, UserResponse
from pydantic import BaseModel, ConfigDict
@ -124,20 +124,12 @@ class ModelModel(BaseModel):
####################
class ModelResponse(BaseModel):
id: str
user_id: str
base_model_id: Optional[str] = None
class ModelUserResponse(ModelModel):
user: Optional[UserResponse] = None
name: str
params: ModelParams
meta: ModelMeta
access_control: Optional[dict] = None
is_active: bool
updated_at: int # timestamp in epoch
created_at: int # timestamp in epoch
class ModelResponse(ModelModel):
pass
class ModelForm(BaseModel):
@ -181,10 +173,15 @@ class ModelsTable:
with get_db() as db:
return [ModelModel.model_validate(model) for model in db.query(Model).all()]
def get_models(self) -> list[ModelModel]:
def get_models(self) -> list[ModelUserResponse]:
with get_db() as db:
return [
ModelModel.model_validate(model)
ModelUserResponse.model_validate(
{
**ModelModel.model_validate(model).model_dump(),
"user": Users.get_user_by_id(model.user_id).model_dump(),
}
)
for model in db.query(Model).filter(Model.base_model_id != None).all()
]
@ -197,8 +194,8 @@ class ModelsTable:
def get_models_by_user_id(
self, user_id: str, permission: str = "write"
) -> list[ModelModel]:
models = self.get_all_models()
) -> list[ModelUserResponse]:
models = self.get_models()
return [
model
for model in models

View File

@ -62,6 +62,14 @@ class UserModel(BaseModel):
####################
class UserResponse(BaseModel):
id: str
name: str
email: str
role: str
profile_image_url: str
class UserRoleUpdateForm(BaseModel):
id: str
role: str

View File

@ -4,6 +4,7 @@ from open_webui.apps.webui.models.models import (
ModelForm,
ModelModel,
ModelResponse,
ModelUserResponse,
Models,
)
from open_webui.constants import ERROR_MESSAGES
@ -22,7 +23,7 @@ router = APIRouter()
###########################
@router.get("/", response_model=list[ModelResponse])
@router.get("/", response_model=list[ModelUserResponse])
async def get_models(id: Optional[str] = None, user=Depends(get_verified_user)):
if user.role == "admin":
return Models.get_models()

View File

@ -284,8 +284,13 @@
>
<div class=" font-semibold line-clamp-1">{model.name}</div>
</Tooltip>
<div class=" text-xs overflow-hidden text-ellipsis line-clamp-1 text-gray-500">
{model?.meta?.description ?? model.id}
<div class="flex gap-1 text-xs overflow-hidden">
<Tooltip content={model?.user?.email} className="flex shrink-0" placement="top-start">
<div class="shrink-0 text-gray-500">
By <span class=" capitalize">{model?.user?.name ?? model?.user?.email}</span>
</div>
</Tooltip>
</div>
</div>
</a>