Skip to content

Commit 3ae1d7f

Browse files
committed
fix: prevent duplicate content when continuing a truncated response
1 parent 0f1b3b0 commit 3ae1d7f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

backend/open_webui/utils/middleware.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2101,7 +2101,14 @@ async def process_chat_payload(request, form_data, user, metadata, model):
21012101
parent_message_id = metadata.get('parent_message_id')
21022102

21032103
if chat_id and parent_message_id and not chat_id.startswith('local:'):
2104-
db_messages = load_messages_from_db(chat_id, parent_message_id)
2104+
# Load up to message_id if it already exists in the DB (the continue case).
2105+
msg_id = metadata.get('message_id')
2106+
load_up_to_id = (
2107+
msg_id
2108+
if msg_id and Chats.get_message_by_id_and_message_id(chat_id, msg_id)
2109+
else parent_message_id
2110+
)
2111+
db_messages = load_messages_from_db(chat_id, load_up_to_id)
21052112
if db_messages:
21062113
system_message = get_system_message(form_data.get('messages', []))
21072114
form_data['messages'] = [system_message, *db_messages] if system_message else db_messages

0 commit comments

Comments
 (0)