mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
Backport of #50276 to lts/1.108.x. tests/integration/_support/redaction_probe.py also sends the standard key the picked integration test reads (main's probe got it in #47192).
Cherry-picked from 3f13c1ca34 (main). Conflicts in litellm_logging.py and the prompt caching check test were main-only neighbours (_get_completed_success_callbacks and the tools/system affinity tests), resolved by adding only this PR's method and test.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import json
|
|
import os
|
|
from collections.abc import Mapping
|
|
from datetime import datetime
|
|
from typing import Final
|
|
|
|
import httpx
|
|
from pydantic import BaseModel
|
|
|
|
from litellm.integrations.custom_logger import CustomLogger
|
|
|
|
|
|
def _payload(kwargs: Mapping[str, object], response_obj: object) -> str:
|
|
params: Final = kwargs.get("litellm_params")
|
|
request: Final = params.get("proxy_server_request") if isinstance(params, Mapping) else None
|
|
standard: Final = kwargs.get("standard_logging_object")
|
|
return json.dumps(
|
|
{
|
|
"request": request,
|
|
"response": response_obj.model_dump() if isinstance(response_obj, BaseModel) else response_obj,
|
|
"standard_response": standard.get("response") if isinstance(standard, Mapping) else None,
|
|
"standard": standard,
|
|
},
|
|
default=str,
|
|
)
|
|
|
|
|
|
class SyncRedactionProbe(CustomLogger):
|
|
def log_success_event(
|
|
self, kwargs: Mapping[str, object], response_obj: object, start_time: datetime, end_time: datetime
|
|
) -> None:
|
|
with httpx.Client(trust_env=False) as client:
|
|
response: Final = client.post(os.environ["REDACTION_PROBE_URL"], content=_payload(kwargs, response_obj))
|
|
response.raise_for_status()
|
|
|
|
|
|
class RedactionProbe(CustomLogger):
|
|
async def async_log_success_event(
|
|
self, kwargs: Mapping[str, object], response_obj: object, start_time: datetime, end_time: datetime
|
|
) -> None:
|
|
async with httpx.AsyncClient(trust_env=False) as client:
|
|
response: Final = await client.post(
|
|
os.environ["REDACTION_PROBE_URL"], content=_payload(kwargs, response_obj)
|
|
)
|
|
response.raise_for_status()
|
|
|
|
|
|
probe: Final = RedactionProbe()
|