mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
use util convert_litellm_response_object_to_dict
This commit is contained in:
parent
22bc70633e
commit
566d51767f
1 changed files with 31 additions and 0 deletions
31
litellm/litellm_core_utils/logging_utils.py
Normal file
31
litellm/litellm_core_utils/logging_utils.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from typing import Any
|
||||
|
||||
import litellm
|
||||
|
||||
"""
|
||||
Helper utils used for logging callbacks
|
||||
"""
|
||||
|
||||
|
||||
ALL_LITELLM_RESPONSE_TYPES = [
|
||||
litellm.ModelResponse,
|
||||
litellm.EmbeddingResponse,
|
||||
litellm.ImageResponse,
|
||||
litellm.TranscriptionResponse,
|
||||
litellm.TextCompletionResponse,
|
||||
]
|
||||
|
||||
|
||||
def convert_litellm_response_object_to_dict(response_obj: Any) -> dict:
|
||||
"""
|
||||
Convert a LiteLLM response object to a dictionary
|
||||
|
||||
"""
|
||||
if isinstance(response_obj, dict):
|
||||
return response_obj
|
||||
for _type in ALL_LITELLM_RESPONSE_TYPES:
|
||||
if isinstance(response_obj, _type):
|
||||
return response_obj.model_dump()
|
||||
|
||||
# If it's not a LiteLLM type, return the object as is
|
||||
return dict(response_obj)
|
||||
Loading…
Add table
Reference in a new issue