Skip to content

Fix AudioChunk.to_openai() serialization for raw audio bytes and prefixed base64 audio strings. #245

Merged
juliendenize merged 3 commits into
mistralai:mainfrom
haoruilee:fix/audiochunk
Jun 16, 2026
Merged

Fix AudioChunk.to_openai() serialization for raw audio bytes and prefixed base64 audio strings. #245
juliendenize merged 3 commits into
mistralai:mainfrom
haoruilee:fix/audiochunk

Conversation

@haoruilee

Copy link
Copy Markdown
Contributor

Summary

Fix AudioChunk.to_openai() serialization for raw audio bytes and prefixed base64 audio strings. Close #244

Root Cause

AudioChunk.to_openai() decoded raw bytes as UTF-8 instead of base64-encoding them, and _detect_audio_format() did not strip data:audio/...;base64, prefixes before base64 decoding.

Tests

  • pytest tests/test_converters.py -q
  • pytest --cov=mistral_common tests/ --ignore=tests/integrations --cov-report "xml:coverage.xml"
  • pytest --doctest-modules ./src
  • pytest tests/integrations/ -v
  • ruff check .
  • ruff format . --check
  • mypy .
  • mkdocs build --strict

@juliendenize juliendenize left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 !

@juliendenize juliendenize merged commit e47abd9 into mistralai:main Jun 16, 2026
12 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: AudioChunk.to_openai() fails for valid raw audio bytes

2 participants