Fix AudioChunk.to_openai() serialization for raw audio bytes and prefixed base64 audio strings. #245
Merged
Merged
Conversation
juliendenize
approved these changes
Jun 16, 2026
juliendenize
left a comment
Contributor
There was a problem hiding this comment.
The PR looks good to me, i made some minor adjustments, thanks for the contribution !
it was a case we didn't tested as evidenced here, so nice of you to fix it !
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
Fix
AudioChunk.to_openai()serialization for raw audio bytes and prefixed base64 audio strings. Close #244Root Cause
AudioChunk.to_openai()decoded raw bytes as UTF-8 instead of base64-encoding them, and_detect_audio_format()did not stripdata:audio/...;base64,prefixes before base64 decoding.Tests
pytest tests/test_converters.py -qpytest --cov=mistral_common tests/ --ignore=tests/integrations --cov-report "xml:coverage.xml"pytest --doctest-modules ./srcpytest tests/integrations/ -vruff check .ruff format . --checkmypy .mkdocs build --strict