diff --git a/backend/open_webui/apps/webui/models/knowledge.py b/backend/open_webui/apps/webui/models/knowledge.py index 16eae7767..e1a13b3fd 100644 --- a/backend/open_webui/apps/webui/models/knowledge.py +++ b/backend/open_webui/apps/webui/models/knowledge.py @@ -128,17 +128,20 @@ class KnowledgeTable: def get_knowledge_bases(self) -> list[KnowledgeUserModel]: with get_db() as db: - return [ - KnowledgeUserModel.model_validate( - { - **KnowledgeModel.model_validate(knowledge).model_dump(), - "user": Users.get_user_by_id(knowledge.user_id).model_dump(), - } + knowledge_bases = [] + for knowledge in ( + db.query(Knowledge).order_by(Knowledge.updated_at.desc()).all() + ): + user = Users.get_user_by_id(knowledge.user_id) + knowledge_bases.append( + KnowledgeUserModel.model_validate( + { + **KnowledgeModel.model_validate(knowledge).model_dump(), + "user": user.model_dump() if user else None, + } + ) ) - for knowledge in db.query(Knowledge) - .order_by(Knowledge.updated_at.desc()) - .all() - ] + return knowledge_bases def get_knowledge_bases_by_user_id( self, user_id: str, permission: str = "write" diff --git a/backend/open_webui/apps/webui/models/models.py b/backend/open_webui/apps/webui/models/models.py index 99e33efbf..50581bc73 100644 --- a/backend/open_webui/apps/webui/models/models.py +++ b/backend/open_webui/apps/webui/models/models.py @@ -175,15 +175,18 @@ class ModelsTable: def get_models(self) -> list[ModelUserResponse]: with get_db() as db: - return [ - ModelUserResponse.model_validate( - { - **ModelModel.model_validate(model).model_dump(), - "user": Users.get_user_by_id(model.user_id).model_dump(), - } + models = [] + for model in db.query(Model).filter(Model.base_model_id != None).all(): + user = Users.get_user_by_id(model.user_id) + models.append( + ModelUserResponse.model_validate( + { + **ModelModel.model_validate(model).model_dump(), + "user": user.model_dump() if user else None, + } + ) ) - for model in db.query(Model).filter(Model.base_model_id != None).all() - ] + return models def get_base_models(self) -> list[ModelModel]: with get_db() as db: diff --git a/backend/open_webui/apps/webui/models/prompts.py b/backend/open_webui/apps/webui/models/prompts.py index fe2ea87da..fe9999195 100644 --- a/backend/open_webui/apps/webui/models/prompts.py +++ b/backend/open_webui/apps/webui/models/prompts.py @@ -103,15 +103,20 @@ class PromptsTable: def get_prompts(self) -> list[PromptUserResponse]: with get_db() as db: - return [ - PromptUserResponse.model_validate( - { - **PromptModel.model_validate(prompt).model_dump(), - "user": Users.get_user_by_id(prompt.user_id).model_dump(), - } + prompts = [] + + for prompt in db.query(Prompt).order_by(Prompt.timestamp.desc()).all(): + user = Users.get_user_by_id(prompt.user_id) + prompts.append( + PromptUserResponse.model_validate( + { + **PromptModel.model_validate(prompt).model_dump(), + "user": user.model_dump() if user else None, + } + ) ) - for prompt in db.query(Prompt).all() - ] + + return prompts def get_prompts_by_user_id( self, user_id: str, permission: str = "write" diff --git a/backend/open_webui/apps/webui/models/tools.py b/backend/open_webui/apps/webui/models/tools.py index 0044de218..b628f4f9f 100644 --- a/backend/open_webui/apps/webui/models/tools.py +++ b/backend/open_webui/apps/webui/models/tools.py @@ -140,15 +140,18 @@ class ToolsTable: def get_tools(self) -> list[ToolUserResponse]: with get_db() as db: - return [ - ToolUserResponse.model_validate( - { - **ToolModel.model_validate(tool).model_dump(), - "user": Users.get_user_by_id(tool.user_id).model_dump(), - } + tools = [] + for tool in db.query(Tool).order_by(Tool.updated_at.desc()).all(): + user = Users.get_user_by_id(tool.user_id) + tools.append( + ToolUserResponse.model_validate( + { + **ToolModel.model_validate(tool).model_dump(), + "user": user.model_dump() if user else None, + } + ) ) - for tool in db.query(Tool).order_by(Tool.updated_at.desc()).all() - ] + return tools def get_tools_by_user_id( self, user_id: str, permission: str = "write" diff --git a/src/lib/components/workspace/Knowledge.svelte b/src/lib/components/workspace/Knowledge.svelte index b8a936452..c5ea4ad7f 100644 --- a/src/lib/components/workspace/Knowledge.svelte +++ b/src/lib/components/workspace/Knowledge.svelte @@ -165,12 +165,14 @@