mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
enh: restore tags from chat import
This commit is contained in:
parent
30eb43f5b8
commit
d23252b8a9
@ -65,6 +65,7 @@ class ChatForm(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class ChatImportForm(ChatForm):
|
class ChatImportForm(ChatForm):
|
||||||
|
meta: Optional[dict] = {}
|
||||||
pinned: Optional[bool] = False
|
pinned: Optional[bool] = False
|
||||||
folder_id: Optional[str] = None
|
folder_id: Optional[str] = None
|
||||||
|
|
||||||
@ -139,6 +140,7 @@ class ChatTable:
|
|||||||
else "New Chat"
|
else "New Chat"
|
||||||
),
|
),
|
||||||
"chat": form_data.chat,
|
"chat": form_data.chat,
|
||||||
|
"meta": form_data.meta,
|
||||||
"pinned": form_data.pinned,
|
"pinned": form_data.pinned,
|
||||||
"folder_id": form_data.folder_id,
|
"folder_id": form_data.folder_id,
|
||||||
"created_at": int(time.time()),
|
"created_at": int(time.time()),
|
||||||
|
@ -110,6 +110,16 @@ async def create_new_chat(form_data: ChatForm, user=Depends(get_verified_user)):
|
|||||||
async def import_chat(form_data: ChatImportForm, user=Depends(get_verified_user)):
|
async def import_chat(form_data: ChatImportForm, user=Depends(get_verified_user)):
|
||||||
try:
|
try:
|
||||||
chat = Chats.import_chat(user.id, form_data)
|
chat = Chats.import_chat(user.id, form_data)
|
||||||
|
if chat:
|
||||||
|
tags = chat.meta.get("tags", [])
|
||||||
|
for tag_id in tags:
|
||||||
|
tag_id = tag_id.replace(" ", "_").lower()
|
||||||
|
if (
|
||||||
|
tag_id != "none"
|
||||||
|
and Tags.get_tag_by_name_and_user_id(tag_id, user.id) is None
|
||||||
|
):
|
||||||
|
Tags.insert_new_tag(tag_id, user.id)
|
||||||
|
|
||||||
return ChatResponse(**chat.model_dump())
|
return ChatResponse(**chat.model_dump())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
@ -35,6 +35,7 @@ export const createNewChat = async (token: string, chat: object) => {
|
|||||||
export const importChat = async (
|
export const importChat = async (
|
||||||
token: string,
|
token: string,
|
||||||
chat: object,
|
chat: object,
|
||||||
|
meta: object | null,
|
||||||
pinned?: boolean,
|
pinned?: boolean,
|
||||||
folderId?: string | null
|
folderId?: string | null
|
||||||
) => {
|
) => {
|
||||||
@ -49,6 +50,7 @@ export const importChat = async (
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
chat: chat,
|
chat: chat,
|
||||||
|
meta: meta ?? {},
|
||||||
pinned: pinned,
|
pinned: pinned,
|
||||||
folder_id: folderId
|
folder_id: folderId
|
||||||
})
|
})
|
||||||
|
@ -211,8 +211,9 @@
|
|||||||
const importChatHandler = async (items, pinned = false, folderId = null) => {
|
const importChatHandler = async (items, pinned = false, folderId = null) => {
|
||||||
console.log('importChatHandler', items, pinned, folderId);
|
console.log('importChatHandler', items, pinned, folderId);
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
|
console.log(item);
|
||||||
if (item.chat) {
|
if (item.chat) {
|
||||||
await importChat(localStorage.token, item.chat, pinned, folderId);
|
await importChat(localStorage.token, item.chat, item?.meta ?? {}, pinned, folderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user