fix: parse list-of-parts content in ChatMessage.from_openai_dict_format - #12446
Open
Vedant-Agarwal wants to merge 1 commit into
Open
fix: parse list-of-parts content in ChatMessage.from_openai_dict_format#12446Vedant-Agarwal wants to merge 1 commit into
Vedant-Agarwal wants to merge 1 commit into
Conversation
Previously, user/system/developer messages whose content was a list of OpenAI content parts had the list wrapped verbatim in a single TextContent. As a result, msg.text returned a list (violating its str | None contract) and to_dict() / to_openai_dict_format() emitted invalid content. Now user messages convert text parts to TextContent, image_url parts with base64 data URLs to ImageContent (splitting MIME type and base64 payload, preserving detail), and file parts with inline file_data to FileContent (preserving filename). System and developer messages accept lists of text parts. Unsupported parts (non-data image URLs, file_id references, unknown part types) raise ValueError. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Vedant-Agarwal
requested review from
julian-risch
and removed request for
a team
August 24, 2026 08:08
|
@Vedant-Agarwal is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
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.
Related Issues
Proposed Changes:
ChatMessage.from_openai_dict_formatpassed list-of-partscontentverbatim into a singleTextContentforuser,system, anddevelopermessages (only thetoolbranch handled lists). This mademsg.textreturn alist(violating itsstr | Nonecontract) and madeto_dict()/to_openai_dict_format()emit invalid content:This PR makes list parsing the exact inverse of
to_openai_dict_format:textparts becomeTextContent;image_urlparts with base64 data URLs becomeImageContent(MIME type and base64 payload split from the data URL,detailpreserved);fileparts with inlinefile_databecomeFileContent(filenamepreserved). The message is built viaChatMessage.from_user(content_parts=...).textparts are accepted (joined with a newline, sincefrom_systemstores a single text); non-text parts raiseValueError.file_id, unknown part types — raiseValueErrorinstead of silently corrupting the message.String
contentbehaves exactly as before.How did you test it?
Added unit tests in
test/dataclasses/test_chat_message.pycovering: list of text parts, text + image data URL part (withdetail), text + file part, unsupported parts (http image URL,file_idfile, unknown part type), system message with text parts / with non-text parts, and a full multimodal round-tripfrom_openai_dict_format(msg.to_openai_dict_format()) == msg.Notes for the reviewer
_parse_openai_data_url,_from_openai_content_parts) next to_validate_openai_message."\n"is a judgment call — happy to change to rejecting multiple parts if you prefer.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.(AI-assisted: implemented with Claude Code.)