Add litellm call id passing to Aim guardrails on pre and post-hooks calls (#10021)
All checks were successful
Read Version from pyproject.toml / read-version (push) Successful in 16s
Helm unit test / unit-test (push) Successful in 19s

* Add litellm_call_id passing to aim guardrails on pre and post-hooks

* Add test that ensures that pre_call_hook receives litellm call id when common_request_processing called
This commit is contained in:
Michael Leshchinsky 2025-04-16 17:41:28 +03:00 committed by GitHub
parent ca593e003a
commit e19d05980c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 96 additions and 7 deletions

View file

@ -152,6 +152,9 @@ class ProxyBaseLLMRequestProcessing:
):
self.data["model"] = litellm.model_alias_map[self.data["model"]]
self.data["litellm_call_id"] = request.headers.get(
"x-litellm-call-id", str(uuid.uuid4())
)
### CALL HOOKS ### - modify/reject incoming data before calling the model
self.data = await proxy_logging_obj.pre_call_hook( # type: ignore
user_api_key_dict=user_api_key_dict, data=self.data, call_type="completion"
@ -159,9 +162,6 @@ class ProxyBaseLLMRequestProcessing:
## LOGGING OBJECT ## - initialize logging object for logging success/failure events for call
## IMPORTANT Note: - initialize this before running pre-call checks. Ensures we log rejected requests to langfuse.
self.data["litellm_call_id"] = request.headers.get(
"x-litellm-call-id", str(uuid.uuid4())
)
logging_obj, self.data = litellm.utils.function_setup(
original_function=route_type,
rules_obj=litellm.utils.Rules(),
@ -384,7 +384,7 @@ class ProxyBaseLLMRequestProcessing:
@staticmethod
def _get_pre_call_type(
route_type: Literal["acompletion", "aresponses"]
route_type: Literal["acompletion", "aresponses"],
) -> Literal["completion", "responses"]:
if route_type == "acompletion":
return "completion"