소스 검색

enh: filter by untagged chat

Timothy J. Baek 7 달 전
부모
커밋
7476bcaa2b
3개의 변경된 파일32개의 추가작업 그리고 3개의 파일을 삭제
  1. 24 2
      backend/open_webui/apps/webui/models/chats.py
  2. 1 0
      src/lib/components/layout/Sidebar.svelte
  3. 7 1
      src/lib/components/layout/Sidebar/SearchInput.svelte

+ 24 - 2
backend/open_webui/apps/webui/models/chats.py

@@ -480,7 +480,18 @@ class ChatTable:
                 )
 
                 # Check if there are any tags to filter, it should have all the tags
-                if tag_ids:
+                if "none" in tag_ids:
+                    query = query.filter(
+                        text(
+                            """
+                            NOT EXISTS (
+                                SELECT 1
+                                FROM json_each(Chat.meta, '$.tags') AS tag
+                            )
+                            """
+                        )
+                    )
+                elif tag_ids:
                     query = query.filter(
                         and_(
                             *[
@@ -518,7 +529,18 @@ class ChatTable:
                 )
 
                 # Check if there are any tags to filter, it should have all the tags
-                if tag_ids:
+                if "none" in tag_ids:
+                    query = query.filter(
+                        text(
+                            """
+                            NOT EXISTS (
+                                SELECT 1
+                                FROM json_array_elements_text(Chat.meta->'tags') AS tag
+                            )
+                            """
+                        )
+                    )
+                elif tag_ids:
                     query = query.filter(
                         and_(
                             *[

+ 1 - 0
src/lib/components/layout/Sidebar.svelte

@@ -197,6 +197,7 @@
 			return;
 		} else {
 			searchDebounceTimeout = setTimeout(async () => {
+				allChatsLoaded = false;
 				currentChatPage.set(1);
 				await chats.set(await getChatListBySearchText(localStorage.token, search));
 

+ 7 - 1
src/lib/components/layout/Sidebar/SearchInput.svelte

@@ -30,7 +30,13 @@
 
 	let filteredTags = [];
 	$: filteredTags = lastWord.startsWith('tag:')
-		? $tags.filter((tag) => {
+		? [
+				...$tags,
+				{
+					id: 'none',
+					name: $i18n.t('Untagged')
+				}
+			].filter((tag) => {
 				const tagName = lastWord.slice(4);
 				if (tagName) {
 					const tagId = tagName.replace(' ', '_').toLowerCase();