@@ -25,16 +25,22 @@ class AimGuardrailMissingSecrets(Exception):
25
25
26
26
27
27
class AimGuardrail (CustomGuardrail ):
28
- def __init__ (self , api_key : Optional [str ] = None , api_base : Optional [str ] = None , ** kwargs ):
29
- self .async_handler = get_async_httpx_client (llm_provider = httpxSpecialProvider .GuardrailCallback )
28
+ def __init__ (
29
+ self , api_key : Optional [str ] = None , api_base : Optional [str ] = None , ** kwargs
30
+ ):
31
+ self .async_handler = get_async_httpx_client (
32
+ llm_provider = httpxSpecialProvider .GuardrailCallback
33
+ )
30
34
self .api_key = api_key or os .environ .get ("AIM_API_KEY" )
31
35
if not self .api_key :
32
36
msg = (
33
37
"Couldn't get Aim api key, either set the `AIM_API_KEY` in the environment or "
34
38
"pass it as a parameter to the guardrail in the config file"
35
39
)
36
40
raise AimGuardrailMissingSecrets (msg )
37
- self .api_base = api_base or os .environ .get ("AIM_API_BASE" ) or "https://api.aim.security"
41
+ self .api_base = (
42
+ api_base or os .environ .get ("AIM_API_BASE" ) or "https://api.aim.security"
43
+ )
38
44
super ().__init__ (** kwargs )
39
45
40
46
async def async_pre_call_hook (
@@ -68,6 +74,7 @@ async def async_moderation_hook(
68
74
"image_generation" ,
69
75
"moderation" ,
70
76
"audio_transcription" ,
77
+ "responses" ,
71
78
],
72
79
) -> Union [Exception , str , dict , None ]:
73
80
verbose_proxy_logger .debug ("Inside AIM Moderation Hook" )
@@ -77,9 +84,10 @@ async def async_moderation_hook(
77
84
78
85
async def call_aim_guardrail (self , data : dict , hook : str ) -> None :
79
86
user_email = data .get ("metadata" , {}).get ("headers" , {}).get ("x-aim-user-email" )
80
- headers = {"Authorization" : f"Bearer { self .api_key } " , "x-aim-litellm-hook" : hook } | (
81
- {"x-aim-user-email" : user_email } if user_email else {}
82
- )
87
+ headers = {
88
+ "Authorization" : f"Bearer { self .api_key } " ,
89
+ "x-aim-litellm-hook" : hook ,
90
+ } | ({"x-aim-user-email" : user_email } if user_email else {})
83
91
response = await self .async_handler .post (
84
92
f"{ self .api_base } /detect/openai" ,
85
93
headers = headers ,
0 commit comments