Skip to content

Handle audio data URL MIME variants#259

Open
fus3r wants to merge 1 commit into
mistralai:mainfrom
fus3r:fix-audio-data-url-mime-prefix
Open

Handle audio data URL MIME variants#259
fus3r wants to merge 1 commit into
mistralai:mainfrom
fus3r:fix-audio-data-url-mime-prefix

Conversation

@fus3r

@fus3r fus3r commented Jul 6, 2026

Copy link
Copy Markdown

Summary

Audio data URL prefix stripping only matched word-only MIME subtypes. Valid data URLs such as data:audio/x-wav;base64,..., data:audio/vnd.wave;base64,..., and data:audio/wav;codec=pcm;base64,... were left untouched.

That made audio parsing try to base64-decode the full data URL rather than the payload, so valid audio bytes failed with a base64 or audio-format error. This affected both AudioChunk.to_openai() and tokenizer/audio parsing through Audio.from_base64() / Audio.from_audio_chunk(). The same bytes worked when the MIME subtype was simply audio/wav.

This broadens the audio data URL prefix match to allow MIME subtype punctuation and media-type parameters before ;base64,, and makes Audio.from_base64() reuse the same helper as AudioChunk.to_openai(). The parameter match avoids consuming semicolon separators, so malformed inputs with repeated semicolons do not trigger pathological backtracking. The payload and detected format are unchanged.

Testing

  • pytest tests/test_converters.py tests/test_audio.py -q
  • ruff check src/mistral_common/protocol/instruct/chunk.py src/mistral_common/tokens/tokenizers/audio.py tests/test_converters.py tests/test_audio.py
  • ruff format src/mistral_common/protocol/instruct/chunk.py src/mistral_common/tokens/tokenizers/audio.py tests/test_converters.py tests/test_audio.py --check
  • mypy src tests scripts
  • pytest tests/ --ignore=tests/integrations -q
  • pytest --doctest-modules ./src -q
  • mkdocs build --strict
  • pytest tests/integrations/ -q

No related issue. This follows the same audio conversion surface as #245.

@fus3r
fus3r force-pushed the fix-audio-data-url-mime-prefix branch from 8247a2a to 76480fc Compare July 6, 2026 12:30
@fus3r
fus3r marked this pull request as ready for review July 6, 2026 12:42
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.

1 participant