Repository navigation
fix(openai): handle string format for image_url in chat completions - #2213
Merged
caroger merged 6 commits intoOct 7, 2025
Merged
Conversation
axiomofjoy
approved these changes
Sep 18, 2025
axiomofjoy
left a comment
Contributor
There was a problem hiding this comment.
Comments feel a bit verbose
Comment on lines
+1186
to
+1195
| respx_mock.post(url).mock( | ||
| return_value=Response( | ||
| status_code=200, | ||
| json={ | ||
| "choices": [{"index": 0, "message": output_messages[0], "finish_reason": "stop"}], | ||
| "model": model_name, | ||
| "usage": completion_usage, | ||
| }, | ||
| ) | ||
| ) |
Contributor
There was a problem hiding this comment.
Any reason not to use vcrpy instead of a manual mock?
| content_type_attr = attributes.get(content_type_key) | ||
| assert content_type_attr == "image" | ||
|
|
||
| # Clean up for other tests |
Contributor
There was a problem hiding this comment.
This comment seems wrong? What kind of clean up is this doing since this is the end of the test?
caroger
deleted the
2188-bug-openai-instrumentation-error-on-message-images
branch
October 7, 2025 17:29
Merged
This was referenced Nov 26, 2026
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 issue #2188 where OpenAI instrumentation crashed with a
ValueErrorwhen users passedimage_urlas a string instead of a dictionary.Changes
_get_attributes_from_image()to handle both string and dict formats:"image_url": "https://example.com/image.png"(was causing crash)"image_url": {"url": "https://example.com/image.png"}(was working)Root Cause
The
dict(image)call in_get_attributes_from_image()failed whenimagewas a string, causing:ValueError: dictionary update sequence element #0 has length 1; 2 is requiredNote
Support
image_urlprovided as either a string or dict in chat completions and add tests to verify both formats._get_attributes_from_imageto acceptUnion[Mapping[str, Any], str]and extractImageAttributes.IMAGE_URLfrom either a stringimage_urlor a dict withurl.image_urlformats are captured correctly in span attributes.Written by Cursor Bugbot for commit 0004b56. This will update automatically on new commits. Configure here.