mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix: coerce server_tool_use dict to ServerToolUse in Usage.__init__ (#26153)
This commit is contained in:
parent
6ff668c7aa
commit
0baf01b90e
1 changed files with 12 additions and 1 deletions
|
|
@ -1655,7 +1655,18 @@ class Usage(SafeAttributeModel, CompletionUsage):
|
|||
)
|
||||
|
||||
if server_tool_use is not None:
|
||||
self.server_tool_use = server_tool_use
|
||||
# Coerce dict -> ServerToolUse so downstream cost-calc code can
|
||||
# safely access attributes (e.g. .web_search_requests). Some
|
||||
# streaming paths round-trip Usage through ``model_dump()`` and
|
||||
# then re-construct with ``Usage(**dump)``, which would otherwise
|
||||
# leave server_tool_use as a plain dict.
|
||||
# See https://github.com/BerriAI/litellm/issues/26153.
|
||||
if isinstance(server_tool_use, dict):
|
||||
self.server_tool_use = ServerToolUse(**server_tool_use)
|
||||
elif isinstance(server_tool_use, ServerToolUse):
|
||||
self.server_tool_use = server_tool_use
|
||||
else:
|
||||
self.server_tool_use = ServerToolUse.model_validate(server_tool_use)
|
||||
else: # maintain openai compatibility in usage object if possible
|
||||
del self.server_tool_use
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue