Consolidate multimodal ContentChunk support for all message roles#241
Merged
Conversation
This was referenced Jun 5, 2026
212e214 to
b71292f
Compare
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
joa-stdn
reviewed
Jun 8, 2026
Add per-role content type aliases: AssistantContentChunk, SystemContentChunk, ToolContentChunk. Widen all message content fields to use per-role aliases. Add shared _content_to_openai/_content_from_openai helpers on BaseMessage. Refactor all to_openai/from_openai to use shared helpers. Add normalizer _narrow_*_content methods with version-aware validation: - _narrow_assistant_content: pre-V15 allows TextChunk/ThinkChunk, V15 allows all - _narrow_tool_content: pre-V15 allows text only, V15 allows all - _narrow_system_content: V7+ allows text/think/audio, V15 rejects ThinkChunk Widen encode_tool/assistant/system_message return types to tuple[list[int], list[np.ndarray], list[Audio]]. Add TemplateConfig properties: tool_supports_multimodal, assistant_supports_multimodal, system_supports_audio, system_supports_thinking. Update template generation with dynamic supported_types_desc. Closes #236, closes #237, closes #238
b71292f to
16ecf70
Compare
34452dd to
864d127
Compare
joa-stdn
reviewed
Jun 11, 2026
joa-stdn
reviewed
Jun 11, 2026
|
|
||
| Returns: | ||
| String content as-is, list of chunks serialized via each chunk's | ||
| to_openai(), or None. |
joa-stdn
reviewed
Jun 11, 2026
joa-stdn
reviewed
Jun 11, 2026
joa-stdn
reviewed
Jun 11, 2026
… validator-concern tests
joa-stdn
reviewed
Jun 15, 2026
joa-stdn
reviewed
Jun 15, 2026
joa-stdn
reviewed
Jun 15, 2026
joa-stdn
reviewed
Jun 15, 2026
joa-stdn
reviewed
Jun 15, 2026
| tool_messages: list[ToolMessageType] = [] | ||
| for message in messages: | ||
| assert isinstance(message, self._tool_message_class), "Expected tool message" | ||
| content = self._aggregate_content_chunks([message]) |
Contributor
There was a problem hiding this comment.
why can't we run super here?
Contributor
Author
There was a problem hiding this comment.
Because the super one asserts that the content is a string whereas the one in v15 doesn't
joa-stdn
approved these changes
Jun 15, 2026
Halcyonhal9
added a commit
to Halcyonhal9/mistral-common
that referenced
this pull request
Jun 20, 2026
Resolve conflicts from mistralai#241 (consolidated ContentChunk, removed UserContentChunk) and mistralai#245 (audio data URL handling): - chunk.py: apply Responses-API content-type aliases on top of the consolidated ContentChunk; drop the removed UserContentChunk alias. - tests/test_converters.py: keep both ChunkTypes and ContentChunk imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Consolidates PRs #236, #237, #238 into a single PR. Adds multimodal
ContentChunksupport for all message roles with version-gated validation and comprehensive test refactoring.Changes
Content type system
AssistantContentChunk,SystemContentChunk,ToolContentChunkcontentfields to use per-role aliases (matching internal repo)_content_to_openai/_content_from_openaihelpers onBaseMessageto_openai/from_openaito use shared helpers (no role parsing)ToolContentChunktype alias in_parse_tool_contentsignatureNormalizer validation
_narrow_assistant_contentwith version-aware validation:_narrow_tool_contentvalidation:_narrow_system_contentvalidation:Encoding
encode_tool/system_messagereturn types totuple[list[int], list[np.ndarray], list[Audio]]encode_system_messagereturn type to exclude imagesChat templates
TemplateConfigproperties:tool_supports_multimodal,system_supports_audio,system_supports_thinkingsupported_types_desctest_parityto use_get_conversationswithto_openaiconversionAssistantMessage.to_openaireasoning format to handle multimodal contentVersion Gating
Test refactoring
TestChatCompletionRequestNormalizationV7/V13/V15), eliminating standalone test classesInstructRequest[ChatMessage, Tool]output (messages, system_prompt, settings, etc.) instead of individual message fieldsmatchstrings to allpytest.raisescalls for precise error verificationreasoning_effortextraction in test_parityCloses #236, closes #237, closes #238