feat(router): honor per-deployment model_info for continuation prefill capability

The deployment filter only read supports_assistant_prefill from the cost map, so
a model configured with `model_info: {supports_assistant_prefill: true}` on the
deployment (the usual way to declare a capability for a model that is not in the
cost map, or to override it) was wrongly skipped. Check the deployment's
model_info first (True or False both authoritative), then fall back to the cost
map. Adds tests for the override in both directions.
This commit is contained in:
Ayush 2026-09-16 00:05:26 +05:30
parent 8543b3cafd
commit 177f65a89d
2 changed files with 32 additions and 0 deletions

View file

@ -35,6 +35,19 @@ _STR_KEYED_DICT_ADAPTER: Final = TypeAdapter(dict[str, object])
def _deployment_supports_prefill(deployment: object) -> bool:
try:
deployment_map: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment)
except ValidationError:
return False
# A per-deployment model_info override wins, so a model that is not in the cost
# map (or is registered generically) can still opt in or out explicitly with
# `model_info: {"supports_assistant_prefill": true|false}`.
try:
model_info: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment_map.get("model_info"))
declared: Final = model_info.get("supports_assistant_prefill")
if isinstance(declared, bool):
return declared
except ValidationError:
pass
try:
litellm_params: Final = _STR_KEYED_DICT_ADAPTER.validate_python(deployment_map.get("litellm_params"))
except ValidationError:
return False

View file

@ -20,6 +20,25 @@ def test_deployment_supports_prefill_reads_capability():
assert _deployment_supports_prefill(_deployment(NON_PREFILL_MODEL, "b")) is False
def test_deployment_model_info_override_wins_over_cost_map():
# model_info True opts in a model that is not in the cost map
assert (
_deployment_supports_prefill(
{"litellm_params": {"model": "vendor/custom-model"}, "model_info": {"supports_assistant_prefill": True}}
)
is True
)
# model_info False opts out a model the cost map would otherwise allow
assert (
_deployment_supports_prefill(
{"litellm_params": {"model": PREFILL_MODEL}, "model_info": {"supports_assistant_prefill": False}}
)
is False
)
# model_info without the key falls through to the cost map
assert _deployment_supports_prefill(_deployment(PREFILL_MODEL, "z")) is True
def test_deployment_supports_prefill_rejects_malformed_deployments():
assert _deployment_supports_prefill({}) is False
assert _deployment_supports_prefill({"litellm_params": {}}) is False