fix(health): use structured responses input

This commit is contained in:
afoninsky 2026-04-08 22:45:11 +02:00
parent bcde4729f8
commit 08d62c8f1f
No known key found for this signature in database
GPG key ID: 79690EED417BC43E
2 changed files with 54 additions and 2 deletions

View file

@ -106,6 +106,21 @@ class HealthCheckHelpers:
else:
return await litellm.acompletion(**model_params)
@staticmethod
def _get_responses_health_check_input(
prompt: Optional[str] = None,
input: Optional[list] = None,
) -> list:
if input is not None:
return input
return [
{
"role": "user",
"content": [{"type": "input_text", "text": prompt or "test"}],
}
]
@staticmethod
def get_mode_handlers(
model: str,
@ -207,7 +222,10 @@ class HealthCheckHelpers:
),
"responses": lambda: litellm.aresponses(
**_filter_model_params(model_params=model_params),
input=prompt or "test",
input=HealthCheckHelpers._get_responses_health_check_input(
prompt=prompt,
input=input,
),
),
"ocr": lambda: litellm.aocr(
**_filter_model_params(model_params=model_params),

View file

@ -82,6 +82,40 @@ def test_get_litellm_internal_health_check_user_api_key_auth():
assert result.team_alias == LITTELM_INTERNAL_HEALTH_SERVICE_ACCOUNT_NAME
def test_get_responses_health_check_input_wraps_prompt_in_responses_message():
result = HealthCheckHelpers._get_responses_health_check_input(prompt="ping")
assert result == [
{
"role": "user",
"content": [{"type": "input_text", "text": "ping"}],
}
]
@pytest.mark.asyncio
async def test_get_mode_handlers_responses_uses_structured_responses_input():
with patch("litellm.aresponses", new_callable=AsyncMock) as mock_aresponses:
mock_aresponses.return_value = {"status": "ok"}
handler = HealthCheckHelpers.get_mode_handlers(
model="chatgpt/gpt-5.4",
custom_llm_provider="chatgpt",
model_params={"model": "chatgpt/gpt-5.4"},
prompt="health test",
)["responses"]
await handler()
mock_aresponses.assert_awaited_once()
assert mock_aresponses.await_args.kwargs["input"] == [
{
"role": "user",
"content": [{"type": "input_text", "text": "health test"}],
}
]
@pytest.mark.asyncio
async def test_ahealth_check_failure_masks_raw_request_headers():
"""
@ -134,4 +168,4 @@ async def test_ahealth_check_failure_masks_raw_request_headers():
if "Content-Type" in headers:
assert headers["Content-Type"] == "application/json"
print(f"Masked Authorization header: {headers.get('Authorization', 'NOT FOUND')}")
print(f"Masked Authorization header: {headers.get('Authorization', 'NOT FOUND')}")