Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion tests/e2e/llm_translation/endpoints_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,30 @@ class ResponsesFunctionTool(BaseModel):
parameters: FunctionParameters


class ResponsesInputTextPart(BaseModel):
type: Literal["input_text"] = "input_text"
text: str


class ResponsesInputImagePart(BaseModel):
type: Literal["input_image"] = "input_image"
image_url: str


ResponsesInputContentPart = ResponsesInputTextPart | ResponsesInputImagePart


class ResponsesInputMessage(BaseModel):
role: Literal["user", "assistant", "system"] = "user"
content: list[ResponsesInputContentPart]


ResponsesInput = str | list[ResponsesInputMessage]


class ResponsesRequest(BaseModel):
model: str
input: str
input: ResponsesInput
instructions: str | None = None
stream: bool = False
tools: list[ResponsesFunctionTool] | None = None
Expand Down Expand Up @@ -236,6 +257,26 @@ def responses(
stream=stream,
)

def responses_vision(
self, key: str, model: str, text: str, image_url: str
) -> StreamingResponse:
return self._send(
"/v1/responses",
key,
ResponsesRequest(
model=model,
input=[
ResponsesInputMessage(
content=[
ResponsesInputTextPart(text=text),
ResponsesInputImagePart(image_url=image_url),
]
)
],
instructions="You are a helpful assistant",
),
)

def responses_with_tools(
self, key: str, model: str, text: str, tools: list[ResponsesFunctionTool]
) -> StreamingResponse:
Expand Down
46 changes: 46 additions & 0 deletions tests/e2e/llm_translation/test_responses_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,52 @@ def test_responses_returns_function_call(
arguments = WeatherArguments.model_validate(raw_arguments)
assert arguments.location, f"function call arguments missing location: {function_call.arguments}"

@pytest.mark.covers("llm.responses.openai.vision.nonstream.works")
def test_responses_vision_describes_image(
self, endpoints_client: EndpointsClient, resources: ResourceManager
) -> None:
model = f"e2e-responses-{unique_marker()}"
model_id = endpoints_client.create_model(
model,
LiteLLMParamsBody(model="openai/gpt-4o", api_key="os.environ/OPENAI_API_KEY"),
)
resources.defer(lambda: endpoints_client.delete_model(model_id))
key = resources.key()

result = endpoints_client.responses_vision(
key,
model,
"What animal is shown in this image? Answer in one word",
"https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg",
)
require_successful_call(result)
parsed = ResponsesResult.model_validate_json(result.body)
text = parsed.text.strip().lower()
assert text, f"/responses vision returned no output text: {result.body[:300]}"
assert any(
keyword in text
for keyword in ("cat", "feline")
), f"vision response did not describe the image: {parsed.text[:300]}"
Comment on lines +169 to +172

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Vision assertion keyword coverage is narrow

The assertion only matches "cat" or "feline", so it would fail if the model replies with a different valid single-word answer for that image such as "kitten", "kitty", or a breed name like "persian" or "tabby". Prompt-compliance ("answer in one word") reduces this risk in practice, but extending the keyword list or anchoring the assertion with a broader substring check would make the test more robust against non-deterministic model output.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


@pytest.mark.covers("llm.responses.anthropic.basic.nonstream.works")
def test_responses_anthropic_returns_completion(
self, endpoints_client: EndpointsClient, resources: ResourceManager
) -> None:
model = f"e2e-responses-{unique_marker()}"
model_id = endpoints_client.create_model(
model,
LiteLLMParamsBody(
model="anthropic/claude-haiku-4-5", api_key="os.environ/ANTHROPIC_API_KEY"
),
)
resources.defer(lambda: endpoints_client.delete_model(model_id))
key = resources.key()

result = endpoints_client.responses(key, model, "reply with one word")
require_successful_call(result)
parsed = ResponsesResult.model_validate_json(result.body)
assert parsed.text.strip(), f"/responses returned no output text: {result.body[:300]}"


def _parse_stream_event(
event: str,
Expand Down
Loading