mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(types): coerce dict server_tool_use to ServerToolUse in Usage init
Prerequisite for #27346 (completion_cost AttributeError on streaming Anthropic web_search). #27346's per-chunk coercion is undone by the existing Usage(**returned_usage.model_dump()) reconstruction in calculate_usage, which round-trips server_tool_use back to a plain dict; without this Usage.__init__ coercion the cost path still does attribute access on a dict and raises. The same prerequisite was bundled into the stable/1.88.x backport of #27346 (24b9655cd4). Content-verified present on litellm_internal_staging via aggregator32c88ca74f(Litellm oss staging 080626, #29932); this restores only the two-line coercion, not the rest of that aggregator. (cherry picked from commit32c88ca74f)
This commit is contained in:
parent
9bd10221bc
commit
24e30b551f
1 changed files with 3 additions and 0 deletions
|
|
@ -1672,6 +1672,9 @@ class Usage(SafeAttributeModel, CompletionUsage):
|
|||
prompt_tokens_details=_prompt_tokens_details or None,
|
||||
)
|
||||
|
||||
if isinstance(server_tool_use, dict):
|
||||
server_tool_use = ServerToolUse(**server_tool_use)
|
||||
|
||||
if server_tool_use is not None:
|
||||
self.server_tool_use = server_tool_use
|
||||
else: # maintain openai compatibility in usage object if possible
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue