fix(router.py): fix mounting logic

This commit is contained in:
Krrish Dholakia 2024-07-02 17:54:32 -07:00
parent a5124b3146
commit 9ce4198fbb

View file

@ -3375,38 +3375,6 @@ class Router:
litellm_params["max_retries"] = max_retries litellm_params["max_retries"] = max_retries
# proxy support # proxy support
import os
import httpx
# Check if the HTTP_PROXY and HTTPS_PROXY environment variables are set and use them accordingly.
# http_proxy = os.getenv("HTTP_PROXY", None)
# https_proxy = os.getenv("HTTPS_PROXY", None)
# no_proxy = os.getenv("NO_PROXY", None)
# Create the proxies dictionary only if the environment variables are set.
sync_proxy_mounts, async_proxy_mounts = create_proxy_transport_and_mounts()
# if http_proxy is not None and https_proxy is not None:
# sync_proxy_mounts = {
# "http://": httpx.HTTPTransport(proxy=httpx.Proxy(url=http_proxy)),
# "https://": httpx.HTTPTransport(proxy=httpx.Proxy(url=https_proxy)),
# }
# async_proxy_mounts = {
# "http://": httpx.AsyncHTTPTransport(
# proxy=httpx.Proxy(url=http_proxy)
# ),
# "https://": httpx.AsyncHTTPTransport(
# proxy=httpx.Proxy(url=https_proxy)
# ),
# }
# # assume no_proxy is a list of comma separated urls
# if no_proxy is not None and isinstance(no_proxy, str):
# no_proxy_urls = no_proxy.split(",")
# for url in no_proxy_urls: # set no-proxy support for specific urls
# sync_proxy_mounts[url] = None # type: ignore
# async_proxy_mounts[url] = None # type: ignore
organization = litellm_params.get("organization", None) organization = litellm_params.get("organization", None)
if isinstance(organization, str) and organization.startswith("os.environ/"): if isinstance(organization, str) and organization.startswith("os.environ/"):
organization_env_name = organization.replace("os.environ/", "") organization_env_name = organization.replace("os.environ/", "")
@ -3452,7 +3420,6 @@ class Router:
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
verify=litellm.ssl_verify, verify=litellm.ssl_verify,
mounts=async_proxy_mounts,
), # type: ignore ), # type: ignore
) )
self.cache.set_cache( self.cache.set_cache(
@ -3471,7 +3438,6 @@ class Router:
timeout=timeout, timeout=timeout,
max_retries=max_retries, max_retries=max_retries,
http_client=httpx.Client( http_client=httpx.Client(
mounts=sync_proxy_mounts,
limits=httpx.Limits( limits=httpx.Limits(
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
@ -3498,7 +3464,6 @@ class Router:
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
verify=litellm.ssl_verify, verify=litellm.ssl_verify,
mounts=async_proxy_mounts,
), # type: ignore ), # type: ignore
) )
self.cache.set_cache( self.cache.set_cache(
@ -3517,7 +3482,6 @@ class Router:
timeout=stream_timeout, timeout=stream_timeout,
max_retries=max_retries, max_retries=max_retries,
http_client=httpx.Client( http_client=httpx.Client(
mounts=sync_proxy_mounts,
limits=httpx.Limits( limits=httpx.Limits(
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
@ -3562,7 +3526,6 @@ class Router:
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
verify=litellm.ssl_verify, verify=litellm.ssl_verify,
mounts=async_proxy_mounts,
), # type: ignore ), # type: ignore
) )
self.cache.set_cache( self.cache.set_cache(
@ -3578,7 +3541,6 @@ class Router:
timeout=timeout, timeout=timeout,
max_retries=max_retries, max_retries=max_retries,
http_client=httpx.Client( http_client=httpx.Client(
mounts=sync_proxy_mounts,
limits=httpx.Limits( limits=httpx.Limits(
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
@ -3603,7 +3565,6 @@ class Router:
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
verify=litellm.ssl_verify, verify=litellm.ssl_verify,
mounts=async_proxy_mounts,
), # type: ignore ), # type: ignore
) )
self.cache.set_cache( self.cache.set_cache(
@ -3619,7 +3580,6 @@ class Router:
timeout=stream_timeout, timeout=stream_timeout,
max_retries=max_retries, max_retries=max_retries,
http_client=httpx.Client( http_client=httpx.Client(
mounts=sync_proxy_mounts,
limits=httpx.Limits( limits=httpx.Limits(
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
@ -3653,7 +3613,6 @@ class Router:
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
verify=litellm.ssl_verify, verify=litellm.ssl_verify,
mounts=async_proxy_mounts,
), # type: ignore ), # type: ignore
) )
self.cache.set_cache( self.cache.set_cache(
@ -3671,7 +3630,6 @@ class Router:
max_retries=max_retries, max_retries=max_retries,
organization=organization, organization=organization,
http_client=httpx.Client( http_client=httpx.Client(
mounts=sync_proxy_mounts,
limits=httpx.Limits( limits=httpx.Limits(
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
@ -3698,7 +3656,6 @@ class Router:
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),
verify=litellm.ssl_verify, verify=litellm.ssl_verify,
mounts=async_proxy_mounts,
), # type: ignore ), # type: ignore
) )
self.cache.set_cache( self.cache.set_cache(
@ -3717,7 +3674,6 @@ class Router:
max_retries=max_retries, max_retries=max_retries,
organization=organization, organization=organization,
http_client=httpx.Client( http_client=httpx.Client(
mounts=sync_proxy_mounts,
limits=httpx.Limits( limits=httpx.Limits(
max_connections=1000, max_keepalive_connections=100 max_connections=1000, max_keepalive_connections=100
), ),