refac
This commit is contained in:
@@ -140,9 +140,11 @@ class ChatMessageTable:
|
|||||||
)
|
)
|
||||||
if "error" in data:
|
if "error" in data:
|
||||||
existing.error = data.get("error")
|
existing.error = data.get("error")
|
||||||
# Extract usage from info.usage if present
|
# Extract usage - check direct field first, then info.usage
|
||||||
info = data.get("info", {})
|
usage = data.get("usage")
|
||||||
usage = info.get("usage") if info else None
|
if not usage:
|
||||||
|
info = data.get("info", {})
|
||||||
|
usage = info.get("usage") if info else None
|
||||||
if usage:
|
if usage:
|
||||||
existing.usage = usage
|
existing.usage = usage
|
||||||
existing.updated_at = now
|
existing.updated_at = now
|
||||||
@@ -151,9 +153,11 @@ class ChatMessageTable:
|
|||||||
return ChatMessageModel.model_validate(existing)
|
return ChatMessageModel.model_validate(existing)
|
||||||
else:
|
else:
|
||||||
# Insert new
|
# Insert new
|
||||||
# Extract usage from info.usage if present
|
# Extract usage - check direct field first, then info.usage
|
||||||
info = data.get("info", {})
|
usage = data.get("usage")
|
||||||
usage = info.get("usage") if info else None
|
if not usage:
|
||||||
|
info = data.get("info", {})
|
||||||
|
usage = info.get("usage") if info else None
|
||||||
message = ChatMessage(
|
message = ChatMessage(
|
||||||
id=message_id,
|
id=message_id,
|
||||||
chat_id=chat_id,
|
chat_id=chat_id,
|
||||||
|
|||||||
@@ -3042,6 +3042,7 @@ async def process_chat_response(
|
|||||||
async def stream_body_handler(response, form_data):
|
async def stream_body_handler(response, form_data):
|
||||||
nonlocal content
|
nonlocal content
|
||||||
nonlocal content_blocks
|
nonlocal content_blocks
|
||||||
|
nonlocal usage
|
||||||
|
|
||||||
response_tool_calls = []
|
response_tool_calls = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user