diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 98b1166ce4..cfcbc004b7 100644 --- a/backend/open_webui/models/chats.py +++ b/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) diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 1f065988fe..2587c5ff8e 100644 --- a/backend/open_webui/routers/chats.py +++ b/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) diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index b8073d94fa..c548a71dc2 100644 --- a/src/lib/apis/chats/index.ts +++ b/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: { diff --git a/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte b/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte index 68688c83f9..5cdf675e36 100644 --- a/src/lib/components/chat/MessageInput/InputMenu/Chats.svelte +++ b/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 []; });