mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(router): preserve screenshot image routing
This commit is contained in:
parent
dfb45ecfda
commit
2b9f03b712
2 changed files with 11 additions and 5 deletions
|
|
@ -238,7 +238,7 @@ def is_non_content_values_set(message: AllMessageValues) -> bool:
|
|||
return any(message.get(key, None) is not None for key in message if key not in ignore_keys)
|
||||
|
||||
|
||||
_IMAGE_CONTENT_PART_TYPES: Final = ("image_url", "input_image", "image")
|
||||
_IMAGE_CONTENT_PART_TYPES: Final = ("image_url", "input_image", "image", "computer_screenshot")
|
||||
_IMAGE_SCAN_MAX_DEPTH: Final = 4
|
||||
|
||||
|
||||
|
|
@ -564,8 +564,8 @@ def _message_contains_image_content(message: object) -> bool:
|
|||
case {"type": "function_call_output" | "custom_tool_call_output" | "tool_result", "output": list()}:
|
||||
output: Final = _CONTENT_PART.validate_python(message)["output"]
|
||||
return _content_parts_contain_image(_CONTENT_PARTS.validate_python(output))
|
||||
case {"type": "computer_call_output", "output": {"type": "computer_screenshot", "image_url": str()}}:
|
||||
return True
|
||||
case {"type": "computer_call_output", "output": dict()}:
|
||||
return _content_parts_contain_image((_CONTENT_PART.validate_python(message)["output"],))
|
||||
case _:
|
||||
return False
|
||||
|
||||
|
|
|
|||
|
|
@ -31826,8 +31826,10 @@ def test_router_warns_when_a_deployment_enforces_endpoints_without_a_list(caplog
|
|||
("/v1/messages", "malformed", {}),
|
||||
("/v1/messages", 5, {}),
|
||||
("/v1/messages", None, {"messages": ["malformed"]}),
|
||||
("/v1/responses", None, {"input": [{"type": "computer_call_output", "output": {"type": "text", "text": "no image"}}]}),
|
||||
("/v1/responses", None, {"input": [{"type": "computer_call_output", "output": "malformed"}]}),
|
||||
],
|
||||
ids=["moderation-list", "embedding-empty-messages", "message-entry", "message-string", "message-number", "kwargs-messages"],
|
||||
ids=["moderation-list", "embedding-empty-messages", "message-entry", "message-string", "message-number", "kwargs-messages", "computer-output-text", "computer-output-string"],
|
||||
)
|
||||
async def test_image_routing_leaves_non_image_and_malformed_requests_to_the_endpoint(
|
||||
mode: str, metadata_key: str | None, route: str, messages: object, request_kwargs: dict[str, object]
|
||||
|
|
@ -31860,8 +31862,12 @@ async def test_image_routing_leaves_non_image_and_malformed_requests_to_the_endp
|
|||
{"input": [{"type": "function_call_output", "call_id": "call_image", "output": [{"type": "input_image", "image_url": "https://example.invalid/image.png"}]}]},
|
||||
{"input": [{"type": "custom_tool_call_output", "call_id": "call_image", "output": [{"type": "input_image", "image_url": "https://example.invalid/image.png"}]}]},
|
||||
{"input": [{"type": "computer_call_output", "call_id": "call_image", "output": {"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}}]},
|
||||
{"input": [{"role": "user", "content": [{"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}]}]},
|
||||
{"input": [{"type": "function_call_output", "call_id": "call_image", "output": [{"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}]}]},
|
||||
{"input": [{"type": "custom_tool_call_output", "call_id": "call_image", "output": [{"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}]}]},
|
||||
{"input": [{"type": "computer_call_output", "call_id": "call_image", "output": {"type": "computer_screenshot", "url": "https://example.invalid/image.png"}}]},
|
||||
],
|
||||
ids=["chat", "responses", "anthropic", "tool-result", "function-output", "custom-output", "computer-output"],
|
||||
ids=["chat", "responses", "anthropic", "tool-result", "function-output", "custom-output", "computer-output", "screenshot-content", "screenshot-function-output", "screenshot-custom-output", "screenshot-url"],
|
||||
)
|
||||
def test_image_routing_inspects_native_request_content_without_translation(request_kwargs: dict[str, object]) -> None:
|
||||
router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue