Merge pull request #5514 from BerriAI/litellm_add_presidio

[Fix-Refactor] support presidio on new guardrails config
This commit is contained in:
Ishaan Jaff 2024-09-04 16:09:54 -07:00 committed by GitHub
commit 4b9163c7dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 778 additions and 13 deletions

View file

@ -25,6 +25,7 @@ from litellm import (
)
from litellm.caching import DualCache, InMemoryCache, S3Cache
from litellm.cost_calculator import _select_model_name_for_cost_calc
from litellm.integrations.custom_guardrail import CustomGuardrail
from litellm.integrations.custom_logger import CustomLogger
from litellm.litellm_core_utils.redact_messages import (
redact_message_input_output_from_logging,
@ -1359,7 +1360,24 @@ class Logging:
## LOGGING HOOK ##
for callback in callbacks:
if isinstance(callback, CustomLogger):
if isinstance(callback, CustomGuardrail):
from litellm.types.guardrails import GuardrailEventHooks
if (
callback.should_run_guardrail(
data=self.model_call_details,
event_type=GuardrailEventHooks.logging_only,
)
is not True
):
continue
self.model_call_details, result = await callback.async_logging_hook(
kwargs=self.model_call_details,
result=result,
call_type=self.call_type,
)
elif isinstance(callback, CustomLogger):
self.model_call_details, result = await callback.async_logging_hook(
kwargs=self.model_call_details,
result=result,