mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
(feat) add response_time
to StandardLoggingPayload - logged on datadog
, gcs_bucket
, s3_bucket
etc (#7199)
* feat - add response_time to slp * test_get_response_time * docs slp * fix test_datadog_logging_http_request
This commit is contained in:
parent
04138c2df7
commit
2185587b4d
6 changed files with 73 additions and 40 deletions
|
@ -2729,6 +2729,30 @@ class StandardLoggingPayloadSetup:
|
|||
return api_base.rstrip("/")
|
||||
return api_base
|
||||
|
||||
@staticmethod
|
||||
def get_response_time(
|
||||
start_time_float: float,
|
||||
end_time_float: float,
|
||||
completion_start_time_float: float,
|
||||
stream: bool,
|
||||
) -> float:
|
||||
"""
|
||||
Get the response time for the LLM response
|
||||
|
||||
Args:
|
||||
start_time_float: float - start time of the LLM call
|
||||
end_time_float: float - end time of the LLM call
|
||||
completion_start_time_float: float - time to first token of the LLM response (for streaming responses)
|
||||
stream: bool - True when a stream response is returned
|
||||
|
||||
Returns:
|
||||
float: The response time for the LLM response
|
||||
"""
|
||||
if stream is True:
|
||||
return completion_start_time_float - start_time_float
|
||||
else:
|
||||
return end_time_float - start_time_float
|
||||
|
||||
|
||||
def get_standard_logging_object_payload(
|
||||
kwargs: Optional[dict],
|
||||
|
@ -2802,6 +2826,12 @@ def get_standard_logging_object_payload(
|
|||
completion_start_time=completion_start_time,
|
||||
)
|
||||
)
|
||||
response_time = StandardLoggingPayloadSetup.get_response_time(
|
||||
start_time_float=start_time_float,
|
||||
end_time_float=end_time_float,
|
||||
completion_start_time_float=completion_start_time_float,
|
||||
stream=kwargs.get("stream", False),
|
||||
)
|
||||
# clean up litellm hidden params
|
||||
clean_hidden_params = StandardLoggingPayloadSetup.get_hidden_params(
|
||||
hidden_params
|
||||
|
@ -2850,6 +2880,7 @@ def get_standard_logging_object_payload(
|
|||
startTime=start_time_float,
|
||||
endTime=end_time_float,
|
||||
completionStartTime=completion_start_time_float,
|
||||
response_time=response_time,
|
||||
model=kwargs.get("model", "") or "",
|
||||
metadata=clean_metadata,
|
||||
cache_key=clean_hidden_params["cache_key"],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue