mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-14 04:08:46 +00:00
fix: deleting a message in the middle of a chat keeps the earlier messages in the model's context
This commit is contained in:
parent
93d25dbe3b
commit
ad4783a8db
1 changed files with 7 additions and 0 deletions
|
|
@ -1372,6 +1372,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:
|
||||
|
|
@ -1382,6 +1383,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