Skip to content

Commit 15883e5

Browse files
committed
refac
1 parent 0e5696d commit 15883e5

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

backend/open_webui/models/chat_messages.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,10 @@ def upsert_message(
169169
info = data.get('info', {})
170170
usage = info.get('usage') if info else None
171171
if usage:
172-
existing.usage = usage
172+
# Deep-merge: preserve existing keys not present in new data
173+
# This prevents background tasks (follow-ups, title, tags)
174+
# from accidentally clearing the primary response's token counts
175+
existing.usage = {**(existing.usage or {}), **usage}
173176
existing.updated_at = now
174177
db.commit()
175178
db.refresh(existing)

backend/open_webui/utils/middleware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4626,6 +4626,7 @@ def restricted_import(name, globals=None, locals=None, fromlist=(), level=0):
46264626
'content': serialize_output(output),
46274627
'output': output,
46284628
'title': title,
4629+
**({'usage': usage} if usage else {}),
46294630
}
46304631

46314632
if not ENABLE_REALTIME_CHAT_SAVE:

0 commit comments

Comments
 (0)