diff --git a/tests/e2e/llm_translation/fixtures/cat.jpg b/tests/e2e/llm_translation/fixtures/cat.jpg new file mode 100644 index 00000000000..103c370b2e2 Binary files /dev/null and b/tests/e2e/llm_translation/fixtures/cat.jpg differ diff --git a/tests/e2e/llm_translation/test_chat_completions_regression_e2e.py b/tests/e2e/llm_translation/test_chat_completions_regression_e2e.py index 156f3393530..584dbce8089 100644 --- a/tests/e2e/llm_translation/test_chat_completions_regression_e2e.py +++ b/tests/e2e/llm_translation/test_chat_completions_regression_e2e.py @@ -16,7 +16,10 @@ via /model/new (Cohere, Gemini, hosted_vllm), each deleted on teardown. from __future__ import annotations +import base64 import os +from pathlib import Path +from typing import Final import pytest from pydantic import BaseModel @@ -79,18 +82,29 @@ def _streamed_tool_call(events: list[str]) -> tuple[str, str]: return name, arguments -CAT_IMAGE_URL = "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg" +_FIXTURES_DIR: Final = Path(__file__).parent / "fixtures" +CAT_IMAGE: Final = _FIXTURES_DIR / "cat.jpg" OPENAI_VISION_BACKEND = "openai/gpt-4o" -# OpenAI caches a shared prompt prefix once it exceeds ~1024 tokens; this is well -# past that, so a repeat call reports cached prompt tokens. + +def _cat_image_data_url() -> str: + """The vision image as a data URL, read from a fixture we own. + + An https URL would make every vision run depend on a third-party host staying + up and unthrottled, and a 429 from that host reads as a gateway failure. It also + changes what is under test per provider: litellm downloads the image itself for + bedrock, while openai is handed the link and fetches it from its own servers. A + data URL removes the host and puts both providers on the same bytes.""" + return "data:image/jpeg;base64," + base64.b64encode(CAT_IMAGE.read_bytes()).decode() + + def _vision_messages() -> list[ChatMessage]: return [ ChatMessage( role="user", content=[ TextContentPart(text="What animal is in this image? Answer in one word."), - ImageContentPart(image_url=ImageUrl(url=CAT_IMAGE_URL)), + ImageContentPart(image_url=ImageUrl(url=_cat_image_data_url())), ], ) ]