Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
a084938d
Commit
a084938d
authored
Aug 04, 2024
by
Timothy J. Baek
Browse files
refac: chatlist skip, limit -> page
parent
a2f9f7c9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
72 additions
and
74 deletions
+72
-74
backend/apps/webui/routers/chats.py
backend/apps/webui/routers/chats.py
+8
-2
src/lib/apis/chats/index.ts
src/lib/apis/chats/index.ts
+7
-2
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+21
-21
src/lib/components/chat/Messages.svelte
src/lib/components/chat/Messages.svelte
+3
-2
src/lib/components/chat/Settings/Chats.svelte
src/lib/components/chat/Settings/Chats.svelte
+1
-1
src/lib/components/chat/Tags.svelte
src/lib/components/chat/Tags.svelte
+3
-4
src/lib/components/layout/Sidebar.svelte
src/lib/components/layout/Sidebar.svelte
+14
-19
src/lib/components/layout/Sidebar/ChatItem.svelte
src/lib/components/layout/Sidebar/ChatItem.svelte
+10
-16
src/lib/stores/index.ts
src/lib/stores/index.ts
+1
-2
src/lib/utils/index.ts
src/lib/utils/index.ts
+4
-5
No files found.
backend/apps/webui/routers/chats.py
View file @
a084938d
...
@@ -43,9 +43,15 @@ router = APIRouter()
...
@@ -43,9 +43,15 @@ router = APIRouter()
@
router
.
get
(
"/"
,
response_model
=
List
[
ChatTitleIdResponse
])
@
router
.
get
(
"/"
,
response_model
=
List
[
ChatTitleIdResponse
])
@
router
.
get
(
"/list"
,
response_model
=
List
[
ChatTitleIdResponse
])
@
router
.
get
(
"/list"
,
response_model
=
List
[
ChatTitleIdResponse
])
async
def
get_session_user_chat_list
(
async
def
get_session_user_chat_list
(
user
=
Depends
(
get_verified_user
),
skip
:
int
=
0
,
limit
:
int
=
-
1
user
=
Depends
(
get_verified_user
),
page
:
Optional
[
int
]
=
None
):
):
return
Chats
.
get_chat_title_id_list_by_user_id
(
user
.
id
,
skip
=
skip
,
limit
=
limit
)
if
page
:
limit
=
20
skip
=
(
page
-
1
)
*
limit
return
Chats
.
get_chat_title_id_list_by_user_id
(
user
.
id
,
skip
=
skip
,
limit
=
limit
)
else
:
return
Chats
.
get_chat_title_id_list_by_user_id
(
user
.
id
)
############################
############################
...
...
src/lib/apis/chats/index.ts
View file @
a084938d
...
@@ -32,10 +32,15 @@ export const createNewChat = async (token: string, chat: object) => {
...
@@ -32,10 +32,15 @@ export const createNewChat = async (token: string, chat: object) => {
return
res
;
return
res
;
};
};
export
const
getChatList
=
async
(
token
:
string
=
''
,
skip
:
number
=
0
,
limit
:
number
=
-
1
)
=>
{
export
const
getChatList
=
async
(
token
:
string
=
''
,
page
:
number
|
null
=
null
)
=>
{
let
error
=
null
;
let
error
=
null
;
const
searchParams
=
new
URLSearchParams
();
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/chats/?skip=
${
skip
}
&limit=
${
limit
}
`
,
{
if
(
page
!==
null
)
{
searchParams
.
append
(
'
page
'
,
`
${
page
}
`
);
}
const
res
=
await
fetch
(
`
${
WEBUI_API_BASE_URL
}
/chats/?
${
searchParams
.
toString
()}
`
,
{
method
:
'
GET
'
,
method
:
'
GET
'
,
headers
:
{
headers
:
{
Accept
:
'
application/json
'
,
Accept
:
'
application/json
'
,
...
...
src/lib/components/chat/Chat.svelte
View file @
a084938d
...
@@ -26,8 +26,7 @@
...
@@ -26,8 +26,7 @@
socket,
socket,
showCallOverlay,
showCallOverlay,
tools,
tools,
pageSkip,
currentChatPage
pageLimit
} from '$lib/stores';
} from '$lib/stores';
import {
import {
convertMessagesToHistory,
convertMessagesToHistory,
...
@@ -423,9 +422,9 @@
...
@@ -423,9 +422,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
}
}
}
}
};
};
...
@@ -471,9 +470,9 @@
...
@@ -471,9 +470,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
}
}
}
}
};
};
...
@@ -633,9 +632,9 @@
...
@@ -633,9 +632,9 @@
tags: [],
tags: [],
timestamp: Date.now()
timestamp: Date.now()
});
});
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
await chatId.set(chat.id);
await chatId.set(chat.id);
} else {
} else {
await chatId.set('local');
await chatId.set('local');
...
@@ -711,7 +710,8 @@
...
@@ -711,7 +710,8 @@
})
})
);
);
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
currentChatPage.set(0);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
return _responses;
return _responses;
};
};
...
@@ -958,9 +958,9 @@
...
@@ -958,9 +958,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
}
}
}
}
} else {
} else {
...
@@ -1227,9 +1227,9 @@
...
@@ -1227,9 +1227,9 @@
params: params,
params: params,
files: chatFiles
files: chatFiles
});
});
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
}
}
}
}
} else {
} else {
...
@@ -1394,9 +1394,9 @@
...
@@ -1394,9 +1394,9 @@
if ($settings.saveChatHistory ?? true) {
if ($settings.saveChatHistory ?? true) {
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
chat = await updateChatById(localStorage.token, _chatId, { title: _title });
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
}
}
};
};
...
...
src/lib/components/chat/Messages.svelte
View file @
a084938d
<script lang="ts">
<script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from 'uuid';
import { chats, config, settings, user as _user, mobile,
pageSkip, pageLimit
} from '$lib/stores';
import { chats, config, settings, user as _user, mobile,
currentChatPage
} from '$lib/stores';
import { tick, getContext, onMount } from 'svelte';
import { tick, getContext, onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import { toast } from 'svelte-sonner';
...
@@ -90,7 +90,8 @@
...
@@ -90,7 +90,8 @@
history: history
history: history
});
});
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
currentChatPage.set(0);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
};
};
const confirmEditResponseMessage = async (messageId, content) => {
const confirmEditResponseMessage = async (messageId, content) => {
...
...
src/lib/components/chat/Settings/Chats.svelte
View file @
a084938d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import fileSaver from 'file-saver';
import fileSaver from 'file-saver';
const { saveAs } = fileSaver;
const { saveAs } = fileSaver;
import { chats, user, settings, scrollPaginationEnabled
, pageSkip, pageLimit
} from '$lib/stores';
import { chats, user, settings, scrollPaginationEnabled } from '$lib/stores';
import {
import {
archiveAllChats,
archiveAllChats,
...
...
src/lib/components/chat/Tags.svelte
View file @
a084938d
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
getTagsById,
getTagsById,
updateChatById
updateChatById
} from '$lib/apis/chats';
} from '$lib/apis/chats';
import { tags as _tags, chats, pinnedChats,
pageSkip, pageLimit
} from '$lib/stores';
import { tags as _tags, chats, pinnedChats,
currentChatPage
} from '$lib/stores';
import { createEventDispatcher, onMount } from 'svelte';
import { createEventDispatcher, onMount } from 'svelte';
const dispatch = createEventDispatcher();
const dispatch = createEventDispatcher();
...
@@ -61,9 +61,8 @@
...
@@ -61,9 +61,8 @@
} else {
} else {
// if the tag we deleted is no longer a valid tag, return to main chat list view
// if the tag we deleted is no longer a valid tag, return to main chat list view
enablePagination();
enablePagination();
await chats.set(
currentChatPage.set(0);
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
await chats.set(await getChatList(localStorage.token, $currentChatPage));
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
}
};
};
...
...
src/lib/components/layout/Sidebar.svelte
View file @
a084938d
...
@@ -12,9 +12,8 @@
...
@@ -12,9 +12,8 @@
mobile,
mobile,
showArchivedChats,
showArchivedChats,
pinnedChats,
pinnedChats,
pageSkip,
scrollPaginationEnabled,
pageLimit,
currentChatPage
scrollPaginationEnabled
} from '$lib/stores';
} from '$lib/stores';
import { onMount, getContext, tick } from 'svelte';
import { onMount, getContext, tick } from 'svelte';
...
@@ -60,8 +59,6 @@
...
@@ -60,8 +59,6 @@
let chatListLoading = false;
let chatListLoading = false;
let allChatsLoaded = false;
let allChatsLoaded = false;
pageLimit.set(20);
$: filteredChatList = $chats.filter((chat) => {
$: filteredChatList = $chats.filter((chat) => {
if (search === '') {
if (search === '') {
return true;
return true;
...
@@ -84,8 +81,9 @@
...
@@ -84,8 +81,9 @@
const loadMoreChats = async () => {
const loadMoreChats = async () => {
chatListLoading = true;
chatListLoading = true;
pageSkip.set($pageSkip + 1);
const newChatList = await getChatList(localStorage.token, $pageSkip * $pageLimit, $pageLimit);
currentChatPage.set($currentChatPage + 1);
const newChatList = await getChatList(localStorage.token, $currentChatPage);
// once the bottom of the list has been reached (no results) there is no need to continue querying
// once the bottom of the list has been reached (no results) there is no need to continue querying
allChatsLoaded = newChatList.length === 0;
allChatsLoaded = newChatList.length === 0;
...
@@ -108,7 +106,7 @@
...
@@ -108,7 +106,7 @@
showSidebar.set(window.innerWidth > BREAKPOINT);
showSidebar.set(window.innerWidth > BREAKPOINT);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await chats.set(await getChatList(localStorage.token, $
pageSkip, $pageLimit
));
await chats.set(await getChatList(localStorage.token, $
currentChatPage
));
let touchstart;
let touchstart;
let touchend;
let touchend;
...
@@ -209,9 +207,11 @@
...
@@ -209,9 +207,11 @@
await tick();
await tick();
goto('/');
goto('/');
}
}
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
allChatsLoaded = false;
);
currentChatPage.set(0);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
}
};
};
...
@@ -453,9 +453,6 @@
...
@@ -453,9 +453,6 @@
on:click={async () => {
on:click={async () => {
enablePagination();
enablePagination();
allChatsLoaded = false;
allChatsLoaded = false;
await chats.set(
await getChatList(localStorage.token, $pageSkip * $pageLimit, $pageLimit)
);
}}
}}
>
>
{$i18n.t('all')}
{$i18n.t('all')}
...
@@ -469,11 +466,9 @@
...
@@ -469,11 +466,9 @@
if (chatIds.length === 0) {
if (chatIds.length === 0) {
await tags.set(await getAllChatTags(localStorage.token));
await tags.set(await getAllChatTags(localStorage.token));
chatIds = await getChatList(
// if the tag we deleted is no longer a valid tag, return to main chat list view
localStorage.token,
enablePagination();
$pageSkip * $pageLimit,
allChatsLoaded = false;
$pageLimit
);
}
}
await chats.set(chatIds);
await chats.set(chatIds);
}}
}}
...
...
src/lib/components/layout/Sidebar/ChatItem.svelte
View file @
a084938d
...
@@ -14,15 +14,7 @@
...
@@ -14,15 +14,7 @@
getChatListByTagName,
getChatListByTagName,
updateChatById
updateChatById
} from '$lib/apis/chats';
} from '$lib/apis/chats';
import {
import { chatId, chats, mobile, pinnedChats, showSidebar, currentChatPage } from '$lib/stores';
chatId,
chats,
mobile,
pageSkip,
pageLimit,
pinnedChats,
showSidebar
} from '$lib/stores';
import ChatMenu from './ChatMenu.svelte';
import ChatMenu from './ChatMenu.svelte';
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
...
@@ -48,9 +40,9 @@
...
@@ -48,9 +40,9 @@
await updateChatById(localStorage.token, id, {
await updateChatById(localStorage.token, id, {
title: _title
title: _title
});
});
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
}
};
};
...
@@ -63,16 +55,18 @@
...
@@ -63,16 +55,18 @@
if (res) {
if (res) {
goto(`/c/${res.id}`);
goto(`/c/${res.id}`);
await chats.set(
await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit)
currentChatPage.set(0);
);
await chats.set(await getChatList(localStorage.token, $currentChatPage)
);
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
}
}
};
};
const archiveChatHandler = async (id) => {
const archiveChatHandler = async (id) => {
await archiveChatById(localStorage.token, id);
await archiveChatById(localStorage.token, id);
await chats.set(await getChatList(localStorage.token, 0, $pageSkip * $pageLimit || $pageLimit));
currentChatPage.set(0);
await chats.set(await getChatList(localStorage.token, $currentChatPage));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
await pinnedChats.set(await getChatListByTagName(localStorage.token, 'pinned'));
};
};
...
...
src/lib/stores/index.ts
View file @
a084938d
...
@@ -43,8 +43,7 @@ export const showChangelog = writable(false);
...
@@ -43,8 +43,7 @@ export const showChangelog = writable(false);
export
const
showCallOverlay
=
writable
(
false
);
export
const
showCallOverlay
=
writable
(
false
);
export
const
scrollPaginationEnabled
=
writable
(
true
);
export
const
scrollPaginationEnabled
=
writable
(
true
);
export
const
pageSkip
=
writable
(
0
);
export
const
currentChatPage
=
writable
(
0
);
export
const
pageLimit
=
writable
(
-
1
);
export
type
Model
=
OpenAIModel
|
OllamaModel
;
export
type
Model
=
OpenAIModel
|
OllamaModel
;
...
...
src/lib/utils/index.ts
View file @
a084938d
import
{
v4
as
uuidv4
}
from
'
uuid
'
;
import
{
v4
as
uuidv4
}
from
'
uuid
'
;
import
sha256
from
'
js-sha256
'
;
import
sha256
from
'
js-sha256
'
;
import
{
WEBUI_BASE_URL
}
from
'
$lib/constants
'
;
import
{
WEBUI_BASE_URL
}
from
'
$lib/constants
'
;
import
{
scrollPaginationEnabled
,
pageLimit
,
pageSkip
,
chats
}
from
'
$lib/stores
'
;
import
{
scrollPaginationEnabled
,
chats
,
currentChatPage
}
from
'
$lib/stores
'
;
//////////////////////////
//////////////////////////
// Helper functions
// Helper functions
...
@@ -782,14 +782,13 @@ export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, def
...
@@ -782,14 +782,13 @@ export const bestMatchingLanguage = (supportedLanguages, preferredLanguages, def
};
};
export
const
enablePagination
=
()
=>
{
export
const
enablePagination
=
()
=>
{
// Enable infinite scroll pagination
chats
.
set
([]);
chats
.
set
([]);
currentChatPage
.
set
(
0
);
scrollPaginationEnabled
.
set
(
true
);
scrollPaginationEnabled
.
set
(
true
);
pageLimit
.
set
(
20
);
pageSkip
.
set
(
0
);
};
};
export
const
disablePagination
=
()
=>
{
export
const
disablePagination
=
()
=>
{
// Disable infinite scroll pagination
scrollPaginationEnabled
.
set
(
false
);
scrollPaginationEnabled
.
set
(
false
);
pageLimit
.
set
(
-
1
);
pageSkip
.
set
(
0
);
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment