Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

migrate to use new aim FW API

drorbaron6b78ade91883
diff --git a/litellm/proxy/guardrails/guardrail_hooks/aim/aim.py b/litellm/proxy/guardrails/guardrail_hooks/aim/aim.py
index 621defa2d4c..e40bafcc463 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/aim/aim.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/aim/aim.py
@@ -118,7 +118,7 @@ class AimGuardrail(CustomGuardrail):
litellm_call_id=call_id,
)
response = await self.async_handler.post(
- f"{self.api_base}/detect/openai/v2",
+ f"{self.api_base}/fw/v1/analyze",
headers=headers,
json={"messages": data.get("messages", [])},
)
@@ -183,14 +183,17 @@ class AimGuardrail(CustomGuardrail):
)
call_id = request_data.get("litellm_call_id")
response = await self.async_handler.post(
- f"{self.api_base}/detect/output/v2",
+ f"{self.api_base}/fw/v1/analyze",
headers=self._build_aim_headers(
hook=hook,
key_alias=key_alias,
user_email=user_email,
litellm_call_id=call_id,
),
- json={"output": output, "messages": request_data.get("messages", [])},
+ json={
+ "messages": request_data.get("messages", [])
+ + [{"role": "assistant", "content": output}]
+ },
)
response.raise_for_status()
res = response.json()
diff --git a/tests/local_testing/test_aim_guardrails.py b/tests/local_testing/test_aim_guardrails.py
index b11a424ac3b..3a9b6e9a3d1 100644
--- a/tests/local_testing/test_aim_guardrails.py
+++ b/tests/local_testing/test_aim_guardrails.py
@@ -216,12 +216,13 @@ async def test_post_call__with_anonymized_entities__it_deanonymizes_output():
) as mock_post:
def mock_post_detect_side_effect(url, *args, **kwargs):
- if url.endswith("/detect/openai/v2"):
+ request_body = kwargs.get("json", {})
+ if request_body["messages"][-1]["role"] == "user":
return response_with_detections
- elif url.endswith("/detect/output/v2"):
+ elif request_body["messages"][-1]["role"] == "assistant":
return response_without_detections
else:
- raise ValueError("Unexpected URL: {}".format(url))
+ raise ValueError("Unexpected request: {}".format(request_body))
mock_post.side_effect = mock_post_detect_side_effect