fix(translation): encode Responses image URLs - #663
Conversation
Signed-off-by: alam0rt <sam@samlockart.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. WalkthroughThe Responses codec now converts image sources into scalar URLs or data URLs. Unsupported image sources are omitted with a lossy diagnostic. Tests cover Anthropic base64 and URL image translation. ChangesResponses image translation
Estimated code review effort: 2 (Simple) | ~15 minutes Merge Risk: ⚪ Minimal · up to Responses image requests now encode URLs and base64 images in the required scalar format, with unsupported shapes handled by the existing lossy policy. The covered translation paths are ready to merge. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
A rabbit maps the images bright Comment |
Hey! Just writing here to show that a human is behind this PR. I required this patch (patching it using a Nix overlay) to avoid issues with mixing the different provider APIs via switchyard.
What
Fix OpenAI Responses request encoding for normalized image content.
The buffered Responses codec previously serialized the internal tagged
ImageSourceenum directly intoinput_image.image_url. That produces an object such as{ "type": "raw", "data": ... }, while the Responses API requiresimage_urlto be the scalar URL/data URL.This change maps normalized image sources to the wire form Responses accepts:
data:<media-type>;base64,<payload>data URLs.Regression tests cover Anthropic URL and base64 image blocks translated into OpenAI Responses.
Why
Image-bearing Anthropic requests routed through Switchyard to an OpenAI Responses backend currently emit a malformed
input_imageblock. The route can then fail with an upstream schema error instead of preserving the image.How tested
TDD: added the two regression tests first and confirmed both failed before the codec change with the internal tagged
ImageSourceobject inimage_url; both pass after the fix.uv run ruff check .clean — not run; no Python files changeduv run mypy switchyardclean — not run; no Python files changeduv run pytest tests/green — not run; no Python tests changedRust checks run:
Results: formatting clean; clippy clean; translation suite green, including all 59 request-translation tests.
Checklist
snake_caseof the primary class. — N/A; Rust codec change onlyswitchyard/__init__.py.__all__if intended for downstream use. — N/A; no public Python symbols--helpupdated if customer-facing surface changed. — N/A; bug fix onlySigned-off-by: Your Name <email>) per the DCO.Notes for reviewers
This intentionally preserves the current scalar
image_urloutput shape and does not add support for a Responsesdetailfield. Unmappable raw image sources report lossy conversion through the existing policy hook rather than serializing a malformed internal enum.Summary by CodeRabbit
New Features
Bug Fixes
Tests