fix(vision): reject oversized images before API call, handle file:// URIs, improve 400 errors#6964
Closed
Tranquil-Flow wants to merge 1 commit into
Closed
Conversation
…URIs, improve 400 errors Three fixes for vision_analyze returning cryptic 400 "Invalid request data": 1. Pre-flight base64 size check — base64 inflates data ~33%, so a 3.8 MB file exceeds the 5 MB API limit. Reject early with a clear message instead of letting the provider return a generic 400. 2. Handle file:// URIs — strip the scheme and resolve as a local path. Previously file:///path/to/image.png fell through to the "invalid image source" error since it matched neither is_file() nor http(s). 3. Separate invalid_request errors from "does not support vision" errors so the user gets actionable guidance (resize/compress/retry) instead of a misleading "model does not support vision" message. Closes NousResearch#6677
Contributor
|
Merged via #7654 with authorship preserved. Thanks for the contribution! |
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.
Summary
Fixes three root causes behind
vision_analyzereturning400 Invalid request dataon valid local images:file://URI support —file:///path/to/image.pngpreviously fell through to "invalid image source" because it matched neitherPath.is_file()norhttp(s). The scheme is now stripped and the path resolved as a local file.invalid_requesterrors were lumped into "model does not support vision". They now get a separate, actionable message suggesting the user resize/compress the image.Test plan
TestFileUriSupport::test_file_uri_resolved_as_local_path— file:// URI resolves and succeedsTestFileUriSupport::test_file_uri_nonexistent_gives_error— missing file:// target fails gracefullyTestBase64SizeLimit::test_oversized_image_rejected_before_api_call— 4 MB PNG (>5 MB base64) rejected before LLM callTestBase64SizeLimit::test_small_image_not_rejected— small image passes size checkTestErrorClassification::test_invalid_request_error_gives_image_guidance— 400 error produces resize guidanceCloses #6677