mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
Merge pull request #5288 from BerriAI/litellm_aporia_refactor
[Feat] V2 aporia guardrails litellm
This commit is contained in:
commit
c82714757a
33 changed files with 1078 additions and 337 deletions
|
@ -1,4 +1,12 @@
|
|||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any, Optional, Union
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from litellm import ModelResponse as _ModelResponse
|
||||
|
||||
LiteLLMModelResponse = _ModelResponse
|
||||
else:
|
||||
LiteLLMModelResponse = Any
|
||||
|
||||
|
||||
import litellm
|
||||
|
||||
|
@ -20,3 +28,21 @@ def convert_litellm_response_object_to_dict(response_obj: Any) -> dict:
|
|||
|
||||
# If it's not a LiteLLM type, return the object as is
|
||||
return dict(response_obj)
|
||||
|
||||
|
||||
def convert_litellm_response_object_to_str(
|
||||
response_obj: Union[Any, LiteLLMModelResponse]
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Get the string of the response object from LiteLLM
|
||||
|
||||
"""
|
||||
if isinstance(response_obj, litellm.ModelResponse):
|
||||
response_str = ""
|
||||
for choice in response_obj.choices:
|
||||
if isinstance(choice, litellm.Choices):
|
||||
if choice.message.content and isinstance(choice.message.content, str):
|
||||
response_str += choice.message.content
|
||||
return response_str
|
||||
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue