mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-21 10:15:47 +00:00
fix(streaming): type the dict-usage unpack for the basedpyright gate
Usage(**response_obj["usage"]) unpacks a dict whose value type pyright cannot see, and the delta gate reports that once per typed constructor parameter: five, against the three .get() calls the line replaced. Moving the unpack behind _usage_from_payload keeps the same Usage(**payload) call and is reported once, at the call site, so the rule count ends below its merge base
This commit is contained in:
parent
55bbea9b87
commit
d5fb65f41b
1 changed files with 6 additions and 1 deletions
|
|
@ -1394,7 +1394,7 @@ class CustomStreamWrapper:
|
|||
setattr(
|
||||
model_response,
|
||||
"usage",
|
||||
litellm.Usage(**response_obj["usage"]),
|
||||
_usage_from_payload(response_obj["usage"]),
|
||||
)
|
||||
elif isinstance(response_obj["usage"], Usage):
|
||||
setattr(
|
||||
|
|
@ -2421,6 +2421,11 @@ class CustomStreamWrapper:
|
|||
_strip_sse_data_from_chunk = strip_sse_data_from_chunk
|
||||
|
||||
|
||||
def _usage_from_payload(payload: Mapping[str, Any]) -> Usage:
|
||||
"""Build ``Usage`` from a wire-shaped usage dict, forwarding every key."""
|
||||
return litellm.Usage(**payload)
|
||||
|
||||
|
||||
def _cache_token_count(details: PromptTokensDetailsWrapper | None, keys: tuple[str, ...]) -> int:
|
||||
for key in keys:
|
||||
value = getattr(details, key, None)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue