mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
[Feat] Background Health Checks - Allow disabling background health checks for a specific (#13186)
* disable background health checks for specific models * test_background_health_check_skip_disabled_models * Disable Background Health Checks For Specific Models
This commit is contained in:
parent
65ca4f66f6
commit
79be436c2b
3 changed files with 61 additions and 2 deletions
|
|
@ -219,7 +219,7 @@ Here's how to use it:
|
|||
```
|
||||
general_settings:
|
||||
background_health_checks: True # enable background health checks
|
||||
health_check_interval: 300 # frequency of background health checks
|
||||
health_check_interval: 300 # frequency of background health checks
|
||||
```
|
||||
|
||||
2. Start server
|
||||
|
|
@ -229,7 +229,24 @@ $ litellm /path/to/config.yaml
|
|||
|
||||
3. Query health endpoint:
|
||||
```
|
||||
curl --location 'http://0.0.0.0:4000/health'
|
||||
curl --location 'http://0.0.0.0:4000/health'
|
||||
```
|
||||
|
||||
### Disable Background Health Checks For Specific Models
|
||||
|
||||
Use this if you want to disable background health checks for specific models.
|
||||
|
||||
If `background_health_checks` is enabled you can skip individual models by
|
||||
setting `disable_background_health_check: true` in the model's `model_info`.
|
||||
|
||||
```yaml
|
||||
model_list:
|
||||
- model_name: openai/gpt-4o
|
||||
litellm_params:
|
||||
model: openai/gpt-4o
|
||||
api_key: os.environ/OPENAI_API_KEY
|
||||
model_info:
|
||||
disable_background_health_check: true
|
||||
```
|
||||
|
||||
### Hide details
|
||||
|
|
|
|||
|
|
@ -1353,6 +1353,13 @@ async def _run_background_health_check():
|
|||
# make 1 deep copy of llm_model_list on every health check iteration
|
||||
_llm_model_list = copy.deepcopy(llm_model_list) or []
|
||||
|
||||
# filter out models that have disabled background health checks
|
||||
_llm_model_list = [
|
||||
m
|
||||
for m in _llm_model_list
|
||||
if not m.get("model_info", {}).get("disable_background_health_check", False)
|
||||
]
|
||||
|
||||
healthy_endpoints, unhealthy_endpoints = await perform_health_check(
|
||||
model_list=_llm_model_list, details=health_check_details
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2250,6 +2250,41 @@ async def test_run_background_health_check_reflects_llm_model_list(monkeypatch):
|
|||
assert called_model_lists[1] == test_model_list_2
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_background_health_check_skip_disabled_models(monkeypatch):
|
||||
"""Ensure models with disable_background_health_check are skipped."""
|
||||
import litellm.proxy.proxy_server as proxy_server
|
||||
import copy
|
||||
|
||||
test_model_list = [
|
||||
{"model_name": "model-a"},
|
||||
{"model_name": "model-b", "model_info": {"disable_background_health_check": True}},
|
||||
]
|
||||
called_model_lists = []
|
||||
|
||||
async def fake_perform_health_check(model_list, details):
|
||||
called_model_lists.append(copy.deepcopy(model_list))
|
||||
return (["healthy"], [])
|
||||
|
||||
monkeypatch.setattr(proxy_server, "health_check_interval", 1)
|
||||
monkeypatch.setattr(proxy_server, "health_check_details", None)
|
||||
monkeypatch.setattr(proxy_server, "llm_model_list", copy.deepcopy(test_model_list))
|
||||
monkeypatch.setattr(proxy_server, "perform_health_check", fake_perform_health_check)
|
||||
monkeypatch.setattr(proxy_server, "health_check_results", {})
|
||||
|
||||
async def fake_sleep(interval):
|
||||
raise asyncio.CancelledError()
|
||||
|
||||
monkeypatch.setattr(asyncio, "sleep", fake_sleep)
|
||||
|
||||
try:
|
||||
await proxy_server._run_background_health_check()
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
assert called_model_lists == [[{"model_name": "model-a"}]]
|
||||
|
||||
|
||||
def test_get_timeout_from_request():
|
||||
from litellm.proxy.litellm_pre_call_utils import LiteLLMProxyRequestSetup
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue