mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
refactor(logging): simplify hidden response cost backfill
Clean up metadata initialization and reuse the raw response cost when deciding whether to backfill hidden params. Made-with: Cursor
This commit is contained in:
parent
a3e26ddc5e
commit
a3bf78f230
1 changed files with 5 additions and 6 deletions
|
|
@ -1712,10 +1712,8 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
metadata_hidden_params["response_cost"] = response_cost
|
||||
|
||||
litellm_params = self.model_call_details["litellm_params"]
|
||||
metadata = litellm_params.setdefault("metadata", {})
|
||||
if metadata is None:
|
||||
metadata = {}
|
||||
litellm_params["metadata"] = metadata
|
||||
metadata = litellm_params.get("metadata") or {}
|
||||
litellm_params["metadata"] = metadata
|
||||
metadata["hidden_params"] = metadata_hidden_params
|
||||
|
||||
def _process_hidden_params_and_response_cost(
|
||||
|
|
@ -5433,7 +5431,8 @@ def get_standard_logging_object_payload(
|
|||
## Get model cost information ##
|
||||
base_model = _get_base_model_from_metadata(model_call_details=kwargs)
|
||||
custom_pricing = use_custom_pricing_for_model(litellm_params=litellm_params)
|
||||
response_cost: float = kwargs.get("response_cost", 0) or 0.0
|
||||
raw_response_cost = kwargs.get("response_cost")
|
||||
response_cost: float = raw_response_cost or 0.0
|
||||
|
||||
# clean up litellm hidden params
|
||||
clean_hidden_params = StandardLoggingPayloadSetup.get_hidden_params(
|
||||
|
|
@ -5441,7 +5440,7 @@ def get_standard_logging_object_payload(
|
|||
)
|
||||
if (
|
||||
clean_hidden_params["response_cost"] is None
|
||||
and kwargs.get("response_cost") is not None
|
||||
and raw_response_cost is not None
|
||||
):
|
||||
clean_hidden_params["response_cost"] = response_cost
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue