Procházet zdrojové kódy

fix: pinned chats in ref chat

Timothy Jaeryang Baek před 4 měsíci
rodič
revize
5fe56a862b

+ 3 - 1
backend/open_webui/models/chats.py

@@ -502,6 +502,7 @@ class ChatTable:
         user_id: str,
         include_archived: bool = False,
         include_folders: bool = False,
+        include_pinned: bool = False,
         skip: Optional[int] = None,
         limit: Optional[int] = None,
     ) -> list[ChatTitleIdResponse]:
@@ -511,7 +512,8 @@ class ChatTable:
             if not include_folders:
                 query = query.filter_by(folder_id=None)
 
-            query = query.filter(or_(Chat.pinned == False, Chat.pinned == None))
+            if not include_pinned:
+                query = query.filter(or_(Chat.pinned == False, Chat.pinned == None))
 
             if not include_archived:
                 query = query.filter_by(archived=False)

+ 7 - 2
backend/open_webui/routers/chats.py

@@ -39,6 +39,7 @@ router = APIRouter()
 def get_session_user_chat_list(
     user=Depends(get_verified_user),
     page: Optional[int] = None,
+    include_pinned: Optional[bool] = False,
     include_folders: Optional[bool] = False,
 ):
     try:
@@ -47,11 +48,15 @@ def get_session_user_chat_list(
             skip = (page - 1) * limit
 
             return Chats.get_chat_title_id_list_by_user_id(
-                user.id, include_folders=include_folders, skip=skip, limit=limit
+                user.id,
+                include_folders=include_folders,
+                include_pinned=include_pinned,
+                skip=skip,
+                limit=limit,
             )
         else:
             return Chats.get_chat_title_id_list_by_user_id(
-                user.id, include_folders=include_folders
+                user.id, include_folders=include_folders, include_pinned=include_pinned
             )
     except Exception as e:
         log.exception(e)

+ 5 - 0
src/lib/apis/chats/index.ts

@@ -112,6 +112,7 @@ export const importChat = async (
 export const getChatList = async (
 	token: string = '',
 	page: number | null = null,
+	include_pinned: boolean = false,
 	include_folders: boolean = false
 ) => {
 	let error = null;
@@ -125,6 +126,10 @@ export const getChatList = async (
 		searchParams.append('include_folders', 'true');
 	}
 
+	if (include_pinned) {
+		searchParams.append('include_pinned', 'true');
+	}
+
 	const res = await fetch(`${WEBUI_API_BASE_URL}/chats/?${searchParams.toString()}`, {
 		method: 'GET',
 		headers: {

+ 1 - 1
src/lib/components/chat/MessageInput/InputMenu/Chats.svelte

@@ -31,7 +31,7 @@
 
 	const getItemsPage = async () => {
 		itemsLoading = true;
-		let res = await getChatList(localStorage.token, page, true).catch(() => {
+		let res = await getChatList(localStorage.token, page, true, true).catch(() => {
 			return [];
 		});