mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
fix(router): handle moderation text batch inputs
This commit is contained in:
parent
dddbaa803d
commit
330f36c561
2 changed files with 22 additions and 0 deletions
|
|
@ -14347,6 +14347,14 @@ class Router:
|
|||
from litellm.litellm_core_utils.prompt_templates.common_utils import request_contains_image_content
|
||||
from litellm.litellm_core_utils.prompt_templates.factory import resolve_structured_messages
|
||||
|
||||
input_data: Final = request_kwargs.get("input")
|
||||
if (
|
||||
not messages
|
||||
and isinstance(input_data, list)
|
||||
and all(isinstance(item, str) for item in cast(list[object], input_data))
|
||||
):
|
||||
return False
|
||||
|
||||
structured: Final = resolve_structured_messages(
|
||||
messages=cast(list[dict[str, object]] | None, messages), # cast-ok: chat messages are plain dicts
|
||||
request_kwargs=cast(dict[str, object], request_kwargs), # cast-ok: the resolver only reads the mapping
|
||||
|
|
|
|||
|
|
@ -30099,6 +30099,20 @@ def test_image_routing_drop_declared_text_only_legs_for_responses_input_image():
|
|||
assert _candidate_ids(router, request_kwargs={"input": _IMAGE_RESPONSES_INPUT}) == ["vision"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("messages", "expected"),
|
||||
[(None, ("vision", "declared-text")), (_IMAGE_CHAT, ("vision",))],
|
||||
ids=["text-batch", "image-messages-take-precedence"],
|
||||
)
|
||||
def test_image_routing_handles_text_batch_input_without_overriding_messages(
|
||||
messages: list[dict[str, object]] | None, expected: tuple[str, ...]
|
||||
) -> None:
|
||||
router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG)
|
||||
assert tuple(
|
||||
_candidate_ids(router, messages=messages, request_kwargs={"input": ["safe text", "more safe text"]})
|
||||
) == expected
|
||||
|
||||
|
||||
def test_image_routing_send_image_to_the_group_when_every_leg_is_declared_text_only():
|
||||
other_text_leg = {**_DECLARED_TEXT_LEG, "model_info": {"id": "declared-text-2", "supports_vision": False}}
|
||||
router: Final = _mixed_router(_DECLARED_TEXT_LEG, other_text_leg)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue