From f035d67cbdb2fc1c7f70d2fd3b043705d513b4bf Mon Sep 17 00:00:00 2001 From: Zhibo Zhang Date: Sun, 1 Nov 2026 15:29:28 +0800 Subject: [PATCH] test(router): cover OCR capability filtering Signed-off-by: Zhibo Zhang <24061721@hdu.edu.cn> --- .../test_router/test_router_ocr_capability.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/unit/test_router/test_router_ocr_capability.py diff --git a/tests/unit/test_router/test_router_ocr_capability.py b/tests/unit/test_router/test_router_ocr_capability.py new file mode 100644 index 00000000000..c54e8a520bf --- /dev/null +++ b/tests/unit/test_router/test_router_ocr_capability.py @@ -0,0 +1,45 @@ +import pytest +from litellm import Router + + +def test_router_ocr_capability_gate_skips_chat_fallbacks() -> None: + router = Router( + model_list=[ + { + "model_name": "document-ocr", + "litellm_params": {"model": "openai/gpt-4o"}, + "model_info": {"id": "ocr", "mode": "ocr"}, + }, + { + "model_name": "document-ocr", + "litellm_params": {"model": "openai/gpt-4o-mini"}, + "model_info": {"id": "chat", "mode": "chat"}, + }, + ], + enable_pre_call_checks=True, + ) + + async def aocr(*args, **kwargs): + return None + + async def chat(*args, **kwargs): + return None + + deployments = router.get_model_list(model_name="document-ocr") + chat_deployments = router._pre_call_checks( + model="document-ocr", + healthy_deployments=deployments, + messages=None, + input=None, + request_kwargs={"original_function": chat}, + ) + assert [deployment["model_info"]["id"] for deployment in chat_deployments] == ["ocr", "chat"] + + ocr_deployments = router._pre_call_checks( + model="document-ocr", + healthy_deployments=deployments, + messages=None, + input=None, + request_kwargs={"original_function": aocr}, + ) + assert [deployment["model_info"]["id"] for deployment in ocr_deployments] == ["ocr"]