Repository navigation
Conversation
image(url, detail=...) mapped "low" and "high" and let anything else fall through to DETAIL_AUTO, so image(url, detail="hgh") sent the image at auto resolution with no signal to the caller. Every other literal in the chat API (reasoning_effort, tool_choice, response_format, include, agent_count, service_tier, search mode) and the image and video converters raise ValueError on a value outside the Literal. _image_detail_to_proto matches the three literals plus None, which keeps meaning auto, and raises the same shaped ValueError as the rest. Four new cases fail on main; 877 pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
xai_sdk.chat.image(image_url, *, detail="auto")maps"low"and"high"and lets anything else fall through toDETAIL_AUTO:So
image(url, detail="hgh")ordetail="HIGH"sends the image at auto resolution with no signal to the caller. Every other literal in the chat API raises on a value outside itsLiteral:_reasoning_effort_to_proto,_tool_mode_to_proto,_format_type_to_proto,_include_option_to_proto,_agent_count_to_proto,service_tier_to_proto,SearchParameters._search_mode_to_proto, and the sixconvert_image_*_to_pb/convert_video_*_to_pbhelpers.image()is the one exception.Change
_image_detail_to_protomatchesNone | "auto","low","high"and raisesValueError("Invalid image detail: 'hgh'. Must be one of: ['auto', 'low', 'high']")otherwise, the same shape as the other converters.Nonekeeps meaning auto, since the signature isOptional[ImageDetail]. The three valid values produce the same protos as before;test_chat_append_with_imagesin the sync and aio suites is unchanged and still passes.Tests
Eight cases in
tests/chat_test.py: the four mappings (auto,None,low,high) and four rejections (hgh,HIGH,medium,""). The rejections fail onmain.pytest -n 4: 877 passed;ruff check,ruff format --check,pyrightclean. CHANGELOG entry under Unreleased / Changed; it will need a one-line merge against #232 or #233 if those land first, since each adds to the same section.