From a4d3307a842aceb216b15f0a261339db8e36c95d Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Tue, 22 Oct 2024 10:58:57 +0200 Subject: [PATCH] fix(proxy): allow background health check interval to be any number At the moment the code will only work when the interval is a float, otherwise it will perform health check requests in a tight loop. --- litellm/proxy/proxy_server.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 163d2ff25d..050a04c3d1 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -1341,6 +1341,14 @@ async def _run_background_health_check(): if _llm_model_list is None: return + try: + health_check_interval = float(health_check_interval) # type: ignore Type errors are handled in the exception handler below + except (ValueError, TypeError): + verbose_proxy_logger.error( + f"Not running background health checks due to invalid health_check_interval '{health_check_interval}'." + ) + return + while True: healthy_endpoints, unhealthy_endpoints = await perform_health_check( model_list=_llm_model_list, details=health_check_details @@ -1352,10 +1360,7 @@ async def _run_background_health_check(): health_check_results["healthy_count"] = len(healthy_endpoints) health_check_results["unhealthy_count"] = len(unhealthy_endpoints) - if health_check_interval is not None and isinstance( - health_check_interval, float - ): - await asyncio.sleep(health_check_interval) + await asyncio.sleep(health_check_interval) class ProxyConfig: @@ -1543,7 +1548,7 @@ class ProxyConfig: ## INIT PROXY REDIS USAGE CLIENT ## redis_usage_cache = litellm.cache.cache - + async def get_config(self, config_file_path: Optional[str] = None) -> dict: """ Load config file