mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-16 04:28:36 +00:00
fix: deleting a message in the middle of a chat keeps the earlier messages in the model's context (#32332)
This commit is contained in:
parent
7129cc1d84
commit
29289f5ba6
1 changed files with 7 additions and 0 deletions
|
|
@ -1374,6 +1374,7 @@ class ChatTable:
|
|||
self._repair_chat_current_id(chat)
|
||||
|
||||
history = chat.get('history', {})
|
||||
parent_id = ((history.get('messages') or {}).get(message_id) or {}).get('parentId')
|
||||
deleted_ids = self.delete_message_from_history(history, message_id)
|
||||
await ChatMessages.delete_message_ids_by_chat_id(id, deleted_ids, db=session)
|
||||
if not deleted_ids:
|
||||
|
|
@ -1384,6 +1385,12 @@ class ChatTable:
|
|||
|
||||
return ChatModel.model_validate(chat_item)
|
||||
|
||||
for mid, message in (history.get('messages') or {}).items():
|
||||
if message.get('parentId') == parent_id:
|
||||
await ChatMessages.upsert_message(
|
||||
mid, id, message.get('user_id') or chat_item.user_id, message, db=session
|
||||
)
|
||||
|
||||
chat['history'] = history
|
||||
chat_item.chat = chat
|
||||
chat_item.title = self._clean_null_bytes(chat.get('title', 'New Chat'))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue