refac
This commit is contained in:
@@ -169,7 +169,10 @@ class ChatMessageTable:
|
|||||||
info = data.get('info', {})
|
info = data.get('info', {})
|
||||||
usage = info.get('usage') if info else None
|
usage = info.get('usage') if info else None
|
||||||
if usage:
|
if usage:
|
||||||
existing.usage = usage
|
# Deep-merge: preserve existing keys not present in new data
|
||||||
|
# This prevents background tasks (follow-ups, title, tags)
|
||||||
|
# from accidentally clearing the primary response's token counts
|
||||||
|
existing.usage = {**(existing.usage or {}), **usage}
|
||||||
existing.updated_at = now
|
existing.updated_at = now
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(existing)
|
db.refresh(existing)
|
||||||
|
|||||||
@@ -4626,6 +4626,7 @@ async def streaming_chat_response_handler(response, ctx):
|
|||||||
'content': serialize_output(output),
|
'content': serialize_output(output),
|
||||||
'output': output,
|
'output': output,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
**({'usage': usage} if usage else {}),
|
||||||
}
|
}
|
||||||
|
|
||||||
if not ENABLE_REALTIME_CHAT_SAVE:
|
if not ENABLE_REALTIME_CHAT_SAVE:
|
||||||
|
|||||||
Reference in New Issue
Block a user