mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
refactor: clean up fresh tech debt in responses stream usage cost, bedrock count tokens comments and router return types
Some checks are pending
Some checks are pending
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
96bb57b565
commit
c102fcc213
4 changed files with 6 additions and 9 deletions
|
|
@ -1304,13 +1304,12 @@ async def handle_bedrock_count_tokens(
|
|||
if deployment is not None:
|
||||
model_litellm_params: Final = deployment.get("litellm_params", {})
|
||||
|
||||
# Get the resolved model ID from the configuration
|
||||
if "model" in model_litellm_params:
|
||||
resolved_model = model_litellm_params["model"]
|
||||
|
||||
# Copy all litellm_params - BaseAWSLLM will handle AWS credential discovery
|
||||
for key, value in model_litellm_params.items():
|
||||
if key != "user_api_key_dict": # Don't overwrite user_api_key_dict
|
||||
if key != "user_api_key_dict":
|
||||
litellm_params[key] = value
|
||||
|
||||
verbose_proxy_logger.debug("Count tokens litellm_params: %s", litellm_params)
|
||||
|
|
|
|||
|
|
@ -1010,9 +1010,7 @@ class BaseResponsesAPIStreamingIterator:
|
|||
)
|
||||
if estimate is None:
|
||||
return
|
||||
usage: Final = ResponseAPILoggingUtils._transform_response_api_usage_to_chat_usage( # pyright: ignore[reportPrivateUsage] # same shared transform the success path above uses
|
||||
estimate
|
||||
)
|
||||
usage: Final = ResponseAPILoggingUtils.transform_response_api_usage_to_chat_usage(estimate)
|
||||
served_tier: Final[object] = getattr(self._created_response, "service_tier", None)
|
||||
assembled: Final = ModelResponse(
|
||||
model=self.model, usage=usage, service_tier=served_tier if isinstance(served_tier, str) else None
|
||||
|
|
@ -1854,8 +1852,8 @@ def stamp_responses_usage_cost(
|
|||
return
|
||||
if isinstance(bill, bool) or not isinstance(bill, (int, float)):
|
||||
return
|
||||
if bill > 0 or isinstance(getattr(usage_obj, "cost", None), (int, float)):
|
||||
setattr(usage_obj, "cost", float(bill))
|
||||
if bill > 0 or isinstance(usage_obj.cost, (int, float)):
|
||||
usage_obj.cost = float(bill)
|
||||
|
||||
|
||||
def opening_item_payload(payload: Mapping[str, object]) -> Mapping[str, object]:
|
||||
|
|
|
|||
|
|
@ -2894,7 +2894,7 @@ class Router:
|
|||
self._initialize_core_endpoints()
|
||||
self._initialize_specialized_endpoints()
|
||||
|
||||
def validate_fallbacks(self, fallback_param: Sequence[Mapping[str, object]] | None):
|
||||
def validate_fallbacks(self, fallback_param: Sequence[Mapping[str, object]] | None) -> None:
|
||||
"""
|
||||
Validate the fallbacks parameter.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class ModelRateLimitingCheck(CustomLogger):
|
|||
this check actively enforces those limits across ALL routing strategies.
|
||||
"""
|
||||
|
||||
def __init__(self, dual_cache: DualCache, clock: Callable[[], datetime] = get_utc_datetime):
|
||||
def __init__(self, dual_cache: DualCache, clock: Callable[[], datetime] = get_utc_datetime) -> None:
|
||||
self.dual_cache = dual_cache
|
||||
self.clock = clock
|
||||
# model_ids already warned about itpm/otpm + tpm/rpm on the same deployment,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue