mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-01 02:02:20 +00:00
refactor(guardrails): inject the http handler into the agent 365 initializer instead of assigning it after construction
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
a16073b2aa
commit
ea1fc1986b
2 changed files with 11 additions and 5 deletions
|
|
@ -6,10 +6,16 @@ from litellm.types.guardrails import SupportedGuardrailIntegrations
|
|||
from .agent_365 import Agent365Guardrail
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler
|
||||
from litellm.types.guardrails import Guardrail, LitellmParams
|
||||
|
||||
|
||||
def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail") -> Agent365Guardrail:
|
||||
def initialize_guardrail(
|
||||
litellm_params: "LitellmParams",
|
||||
guardrail: "Guardrail",
|
||||
*,
|
||||
async_handler: "AsyncHTTPHandler | None" = None,
|
||||
) -> Agent365Guardrail:
|
||||
import litellm
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
|
||||
|
|
@ -57,6 +63,7 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"
|
|||
client_secret=client_secret,
|
||||
request_timeout=litellm_params.timeout if litellm_params.timeout is not None else 10.0,
|
||||
unreachable_fallback=litellm_params.unreachable_fallback,
|
||||
async_handler=async_handler,
|
||||
event_hook=litellm_params.mode,
|
||||
default_on=litellm_params.default_on,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -257,11 +257,10 @@ class TestInitializeGuardrail:
|
|||
resource_app_id="00000000-0000-0000-0000-000000000000",
|
||||
agent_id="yaml-agent",
|
||||
)
|
||||
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
|
||||
guardrail: Final = initialize_guardrail(params, {"guardrail_name": "a365-stale"})
|
||||
assert "ignoring api_base, resource_app_id, agent_id" in caplog.text
|
||||
handler: Final = FakeHandler([_token_response(), _allow_response()])
|
||||
guardrail.async_handler = handler
|
||||
with caplog.at_level(logging.WARNING, logger="LiteLLM Proxy"):
|
||||
guardrail: Final = initialize_guardrail(params, {"guardrail_name": "a365-stale"}, async_handler=handler)
|
||||
assert "ignoring api_base, resource_app_id, agent_id" in caplog.text
|
||||
await _run(guardrail, _mcp_data())
|
||||
token_call, evaluate_call = handler.calls
|
||||
assert token_call.url == TOKEN_URL
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue