forked from phoenix/litellm-mirror
fix(router.py): support verify_ssl flag
Fixes https://github.com/BerriAI/litellm/issues/3162#issuecomment-2075273807
This commit is contained in:
parent
7730520fb0
commit
180718c33f
3 changed files with 80 additions and 39 deletions
|
@ -22,12 +22,14 @@ load_dotenv()
|
|||
@pytest.mark.parametrize(
|
||||
"timeout", [10, 1.0, httpx.Timeout(timeout=300.0, connect=20.0)]
|
||||
)
|
||||
def test_router_timeout_init(timeout):
|
||||
@pytest.mark.parametrize("ssl_verify", [True, False])
|
||||
def test_router_timeout_init(timeout, ssl_verify):
|
||||
"""
|
||||
Allow user to pass httpx.Timeout
|
||||
|
||||
related issue - https://github.com/BerriAI/litellm/issues/3162
|
||||
"""
|
||||
litellm.ssl_verify = ssl_verify
|
||||
|
||||
router = Router(
|
||||
model_list=[
|
||||
|
@ -40,14 +42,28 @@ def test_router_timeout_init(timeout):
|
|||
"api_version": os.getenv("AZURE_API_VERSION"),
|
||||
"timeout": timeout,
|
||||
},
|
||||
"model_info": {"id": 1234},
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
router.completion(
|
||||
model="test-model", messages=[{"role": "user", "content": "Hey!"}]
|
||||
model_client = router._get_client(
|
||||
deployment={"model_info": {"id": 1234}}, client_type="sync_client", kwargs={}
|
||||
)
|
||||
|
||||
assert getattr(model_client, "timeout") == timeout
|
||||
|
||||
print(f"vars model_client: {vars(model_client)}")
|
||||
http_client = getattr(model_client, "_client")
|
||||
print(f"http client: {vars(http_client)}, ssl_Verify={ssl_verify}")
|
||||
if ssl_verify == False:
|
||||
assert http_client._transport._pool._ssl_context.verify_mode.name == "CERT_NONE"
|
||||
else:
|
||||
assert (
|
||||
http_client._transport._pool._ssl_context.verify_mode.name
|
||||
== "CERT_REQUIRED"
|
||||
)
|
||||
|
||||
|
||||
def test_exception_raising():
|
||||
# this tests if the router raises an exception when invalid params are set
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue