RandomZ / app /tests /test_photo_vision_openai_format.py
StormShadow308's picture
Prioritize production AI: photo vision fix, HF profile, and inspector on generate.
7fa723a
Raw
History Blame Contribute Delete
1.03 kB
"""OpenAI Chat Completions vision message shape for section photos."""
from __future__ import annotations
from pathlib import Path
from app.services.photo_vision import _openai_vision_image_part, _openai_vision_user_message
def test_vision_uses_image_url_not_input_image(tmp_path: Path) -> None:
img = tmp_path / "x.jpg"
img.write_bytes(b"\xff\xd8\xff")
part = _openai_vision_image_part(img, "image/jpeg")
assert part["type"] == "image_url"
assert "url" in part["image_url"]
assert part["image_url"]["url"].startswith("data:image/jpeg;base64,")
assert "input_image" not in str(part)
def test_vision_user_message_orders_text_then_images(tmp_path: Path) -> None:
img = tmp_path / "y.jpg"
img.write_bytes(b"\xff\xd8\xff")
parts = [_openai_vision_image_part(img, "image/jpeg")]
msg = _openai_vision_user_message("describe", parts)
assert msg["role"] == "user"
content = msg["content"]
assert content[0]["type"] == "text"
assert content[1]["type"] == "image_url"