refac
This commit is contained in:
@@ -1829,6 +1829,7 @@ async def chat_completion(
|
||||
]
|
||||
if user_message_id
|
||||
else [],
|
||||
'files': metadata.get('files') or [],
|
||||
'tags': [],
|
||||
'timestamp': int(time.time() * 1000),
|
||||
},
|
||||
@@ -1861,6 +1862,16 @@ async def chat_completion(
|
||||
detail=ERROR_MESSAGES.DEFAULT(),
|
||||
)
|
||||
|
||||
# Persist chat-level files (knowledge collections, docs, etc.)
|
||||
# The old frontend saveChatHandler did this on every message;
|
||||
# now the backend owns persistence.
|
||||
chat_files = metadata.get('files')
|
||||
if chat_files is not None:
|
||||
existing_chat = await Chats.get_chat_by_id(chat_id)
|
||||
if existing_chat:
|
||||
updated = {**existing_chat.chat, 'files': chat_files}
|
||||
await Chats.update_chat_by_id(chat_id, updated)
|
||||
|
||||
# Save user message to DB
|
||||
user_message = metadata.get('user_message') or {}
|
||||
if user_message and user_message.get('id'):
|
||||
|
||||
@@ -2179,7 +2179,7 @@
|
||||
files.push(
|
||||
...(userMessage?.files ?? []).filter(
|
||||
(item) =>
|
||||
['doc', 'text', 'note', 'chat', 'collection'].includes(item.type) ||
|
||||
['doc', 'text', 'note', 'chat', 'collection', 'folder'].includes(item.type) ||
|
||||
(item.type === 'file' && !(item?.content_type ?? '').startsWith('image/'))
|
||||
)
|
||||
);
|
||||
@@ -2433,18 +2433,12 @@
|
||||
await chats.set(await getChatList(localStorage.token, $currentChatPage));
|
||||
|
||||
// Persist chat-level params (system prompt, advanced
|
||||
// params) and files that the backend doesn't have when
|
||||
// it creates the chat shell. Without this, reloading
|
||||
// loses them. Only patch these fields — avoid writing
|
||||
// history/messages which the backend is updating
|
||||
// concurrently via streaming.
|
||||
if (
|
||||
Object.keys(params).length > 0 ||
|
||||
chatFiles.length > 0
|
||||
) {
|
||||
// params) that the backend doesn't receive in the
|
||||
// chat completion request. Files are now persisted
|
||||
// by the backend at chat creation time.
|
||||
if (Object.keys(params).length > 0) {
|
||||
await updateChatById(localStorage.token, res.chat_id, {
|
||||
params: params,
|
||||
files: chatFiles
|
||||
params: params
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user