mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-24 00:52:24 +00:00
style: Black-format Realtime usage and completion usage merge
Resolve combine_usage_objects and responses/utils wrapping for CI black --check. Restore model_fields comments above completion_tokens_details merge loop. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
a220078c51
commit
ef9a8d86d9
2 changed files with 16 additions and 11 deletions
|
|
@ -2226,20 +2226,17 @@ class BaseTokenUsageProcessor:
|
|||
CompletionTokensDetailsWrapper()
|
||||
)
|
||||
|
||||
# Check what keys exist in the model's completion_tokens_details
|
||||
# Access model_fields on the class, not the instance, to avoid Pydantic 2.11+ deprecation warnings
|
||||
for attr in type(usage.completion_tokens_details).model_fields:
|
||||
if not attr.startswith("_") and not callable(
|
||||
getattr(usage.completion_tokens_details, attr)
|
||||
):
|
||||
current_val = (
|
||||
getattr(combined.completion_tokens_details, attr, 0)
|
||||
or 0
|
||||
getattr(combined.completion_tokens_details, attr, 0) or 0
|
||||
)
|
||||
new_val = (
|
||||
getattr(usage.completion_tokens_details, attr, 0) or 0
|
||||
)
|
||||
if new_val is not None and isinstance(
|
||||
new_val, (int, float)
|
||||
):
|
||||
new_val = getattr(usage.completion_tokens_details, attr, 0) or 0
|
||||
if new_val is not None and isinstance(new_val, (int, float)):
|
||||
setattr(
|
||||
combined.completion_tokens_details,
|
||||
attr,
|
||||
|
|
|
|||
|
|
@ -916,10 +916,18 @@ class ResponseAPILoggingUtils:
|
|||
if isinstance(usage_input, dict):
|
||||
usage_input = dict(usage_input) # shallow copy; avoid mutating caller
|
||||
# Realtime *_token_details → *_tokens_details when unset.
|
||||
if usage_input.get("input_tokens_details") is None and "input_token_details" in usage_input:
|
||||
if (
|
||||
usage_input.get("input_tokens_details") is None
|
||||
and "input_token_details" in usage_input
|
||||
):
|
||||
usage_input["input_tokens_details"] = usage_input["input_token_details"]
|
||||
if usage_input.get("output_tokens_details") is None and "output_token_details" in usage_input:
|
||||
usage_input["output_tokens_details"] = usage_input["output_token_details"]
|
||||
if (
|
||||
usage_input.get("output_tokens_details") is None
|
||||
and "output_token_details" in usage_input
|
||||
):
|
||||
usage_input["output_tokens_details"] = usage_input[
|
||||
"output_token_details"
|
||||
]
|
||||
total_tokens = usage_input.get("total_tokens")
|
||||
if total_tokens is None:
|
||||
input_tokens = usage_input.get("input_tokens")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue