From 033e5c1e002626ce20eb562147b323b6fbed33c5 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Fri, 13 Jun 2025 13:07:41 +0200 Subject: [PATCH] Update chats.py --- backend/open_webui/models/chats.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 71cdd0bef..92da599b3 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -634,7 +634,7 @@ class ChatTable: ).params(title_key=f"%{search_text}%", content_key=search_text) ) - # Tag filtering + # Check if there are any tags to filter, it should have all the tags if "none" in tag_ids: query = query.filter( text( @@ -651,7 +651,13 @@ class ChatTable: and_( *[ text( - f"EXISTS (SELECT 1 FROM json_each(Chat.meta, '$.tags') AS tag WHERE tag.value = :tag_id_{tag_idx})" + f""" + EXISTS ( + SELECT 1 + FROM json_each(Chat.meta, '$.tags') AS tag + WHERE tag.value = :tag_id_{tag_idx} + ) + """ ).params(**{f"tag_id_{tag_idx}": tag_id}) for tag_idx, tag_id in enumerate(tag_ids) ] @@ -675,7 +681,7 @@ class ChatTable: ).params(title_key=f"%{search_text}%", content_key=search_text) ) - # Tag filtering + # Check if there are any tags to filter, it should have all the tags if "none" in tag_ids: query = query.filter( text( @@ -692,7 +698,13 @@ class ChatTable: and_( *[ text( - f"EXISTS (SELECT 1 FROM json_array_elements_text(Chat.meta->'tags') AS tag WHERE tag = :tag_id_{tag_idx})" + f""" + EXISTS ( + SELECT 1 + FROM json_array_elements_text(Chat.meta->'tags') AS tag + WHERE tag = :tag_id_{tag_idx} + ) + """ ).params(**{f"tag_id_{tag_idx}": tag_id}) for tag_idx, tag_id in enumerate(tag_ids) ]