mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
fix: preserve dates for chat imports
Co-Authored-By: conql <49243542+conql@users.noreply.github.com>
This commit is contained in:
parent
3f800c069e
commit
2c6227e4b6
6 changed files with 70 additions and 21 deletions
|
|
@ -72,6 +72,8 @@ class ChatImportForm(ChatForm):
|
|||
meta: Optional[dict] = {}
|
||||
pinned: Optional[bool] = False
|
||||
folder_id: Optional[str] = None
|
||||
created_at: Optional[int] = None
|
||||
updated_at: Optional[int] = None
|
||||
|
||||
|
||||
class ChatTitleMessagesForm(BaseModel):
|
||||
|
|
@ -147,8 +149,16 @@ class ChatTable:
|
|||
"meta": form_data.meta,
|
||||
"pinned": form_data.pinned,
|
||||
"folder_id": form_data.folder_id,
|
||||
"created_at": int(time.time()),
|
||||
"updated_at": int(time.time()),
|
||||
"created_at": (
|
||||
form_data.created_at
|
||||
if form_data.created_at
|
||||
else int(time.time())
|
||||
),
|
||||
"updated_at": (
|
||||
form_data.updated_at
|
||||
if form_data.updated_at
|
||||
else int(time.time())
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ export const importChat = async (
|
|||
chat: object,
|
||||
meta: object | null,
|
||||
pinned?: boolean,
|
||||
folderId?: string | null
|
||||
folderId?: string | null,
|
||||
createdAt: number | null = null,
|
||||
updatedAt: number | null = null
|
||||
) => {
|
||||
let error = null;
|
||||
|
||||
|
|
@ -52,7 +54,9 @@ export const importChat = async (
|
|||
chat: chat,
|
||||
meta: meta ?? {},
|
||||
pinned: pinned,
|
||||
folder_id: folderId
|
||||
folder_id: folderId,
|
||||
created_at: createdAt ?? null,
|
||||
updated_at: updatedAt ?? null
|
||||
})
|
||||
})
|
||||
.then(async (res) => {
|
||||
|
|
|
|||
|
|
@ -55,10 +55,7 @@
|
|||
|
||||
import { generateChatCompletion } from '$lib/apis/ollama';
|
||||
import {
|
||||
addTagById,
|
||||
createNewChat,
|
||||
deleteTagById,
|
||||
deleteTagsById,
|
||||
getAllTags,
|
||||
getChatById,
|
||||
getChatList,
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
import {
|
||||
archiveAllChats,
|
||||
createNewChat,
|
||||
deleteAllChats,
|
||||
getAllChats,
|
||||
getAllUserChats,
|
||||
getChatList
|
||||
getChatList,
|
||||
importChat
|
||||
} from '$lib/apis/chats';
|
||||
import { getImportOrigin, convertOpenAIChats } from '$lib/utils';
|
||||
import { onMount, getContext } from 'svelte';
|
||||
|
|
@ -58,10 +57,18 @@
|
|||
console.log(chat);
|
||||
|
||||
if (chat.chat) {
|
||||
await createNewChat(localStorage.token, chat.chat);
|
||||
await importChat(
|
||||
localStorage.token,
|
||||
chat.chat,
|
||||
chat.meta ?? {},
|
||||
false,
|
||||
null,
|
||||
chat?.created_at ?? null,
|
||||
chat?.updated_at ?? null
|
||||
);
|
||||
} else {
|
||||
await createNewChat(localStorage.token, chat);
|
||||
}
|
||||
// Legacy format
|
||||
await importChat(localStorage.token, chat, {}, false, null);
|
||||
}
|
||||
|
||||
currentChatPage.set(1);
|
||||
|
|
|
|||
|
|
@ -29,14 +29,10 @@
|
|||
const i18n = getContext('i18n');
|
||||
|
||||
import {
|
||||
deleteChatById,
|
||||
getChatList,
|
||||
getAllTags,
|
||||
getChatListBySearchText,
|
||||
createNewChat,
|
||||
getPinnedChatList,
|
||||
toggleChatPinnedStatusById,
|
||||
getChatPinnedStatusById,
|
||||
getChatById,
|
||||
updateChatFolderIdById,
|
||||
importChat
|
||||
|
|
@ -202,7 +198,15 @@
|
|||
for (const item of items) {
|
||||
console.log(item);
|
||||
if (item.chat) {
|
||||
await importChat(localStorage.token, item.chat, item?.meta ?? {}, pinned, folderId);
|
||||
await importChat(
|
||||
localStorage.token,
|
||||
item.chat,
|
||||
item?.meta ?? {},
|
||||
pinned,
|
||||
folderId,
|
||||
item?.created_at ?? null,
|
||||
item?.updated_at ?? null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -735,7 +739,15 @@
|
|||
return null;
|
||||
});
|
||||
if (!chat && item) {
|
||||
chat = await importChat(localStorage.token, item.chat, item?.meta ?? {});
|
||||
chat = await importChat(
|
||||
localStorage.token,
|
||||
item.chat,
|
||||
item?.meta ?? {},
|
||||
false,
|
||||
null,
|
||||
item?.created_at ?? null,
|
||||
item?.updated_at ?? null
|
||||
);
|
||||
}
|
||||
|
||||
if (chat) {
|
||||
|
|
@ -793,7 +805,15 @@
|
|||
return null;
|
||||
});
|
||||
if (!chat && item) {
|
||||
chat = await importChat(localStorage.token, item.chat, item?.meta ?? {});
|
||||
chat = await importChat(
|
||||
localStorage.token,
|
||||
item.chat,
|
||||
item?.meta ?? {},
|
||||
false,
|
||||
null,
|
||||
item?.created_at ?? null,
|
||||
item?.updated_at ?? null
|
||||
);
|
||||
}
|
||||
|
||||
if (chat) {
|
||||
|
|
|
|||
|
|
@ -132,7 +132,18 @@
|
|||
return null;
|
||||
});
|
||||
if (!chat && item) {
|
||||
chat = await importChat(localStorage.token, item.chat, item?.meta ?? {});
|
||||
chat = await importChat(
|
||||
localStorage.token,
|
||||
item.chat,
|
||||
item?.meta ?? {},
|
||||
false,
|
||||
null,
|
||||
item?.created_at ?? null,
|
||||
item?.updated_at ?? null
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
// Move the chat
|
||||
|
|
|
|||
Loading…
Reference in a new issue