Skip to content

Fix percent-encoded audio file URIs - #391

Open
Ehsan-hash wants to merge 1 commit into
mistralai:mainfrom
Ehsan-hash:fix/audio-file-uri-decoding
Open

Ehsan-hash wants to merge 1 commit into
mistralai:mainfrom
Ehsan-hash:fix/audio-file-uri-decoding

Conversation

@Ehsan-hash

Copy link
Copy Markdown

Summary

Closes #390.

Audio.from_file() accepts file URIs, but currently treats percent escapes as literal filename characters. A WAV named clip one.wav loads through its plain path and fails through Path.as_uri(). AudioURLChunk reaches the same loader.

Changes

  • Decode percent escapes once inside the existing file:// branch using urllib.parse.unquote. Plain local paths remain untouched, including filenames containing literal %20.
  • Clarify the accepted file-URI input in the method's docstring.
  • Add generated-WAV regressions for spaces, literal percent escapes, Unicode, plus signs, unescaped filenames, missing files, and the real AudioURLChunk encoder workflow.

The change adds no dependency or new URL/authority handling. It keeps the existing file-prefix routing and audio decoding behavior.

Verification

Tested on macOS with Python 3.12.15, pinned uv 0.12.6, and the frozen all-extras/development environment. Tests use generated audio and offline model caches.

Unchanged source: new regressions fail in five encoded-URI cases; two controls pass.
With the fix: all seven regressions pass, comparing actual samples and sampling rates.
Existing focused audio and AudioURLChunk checks: 36 passed.
Full CI-shaped non-integration suite: 1,329 passed, 16 skipped.
Source doctests: 53 passed.
Ruff check and format, mypy, lock check, and manual pre-commit hooks: passed.
uv sync --frozen --all-extras --group dev --python 3.12
uv run pytest -q tests/unit/tokens/tokenizers/test_audio_file_uri.py
uv run pytest --cov=mistral_common tests/ --ignore=tests/integrations --ignore=tests/integration -n 2 --dist loadfile
uv run pytest --doctest-modules ./src
uv run ruff check .
uv run ruff format --check .
uv run mypy .
uv lock --check
uv run pre-commit run --files src/mistral_common/tokens/tokenizers/audio.py tests/unit/tokens/tokenizers/test_audio_file_uri.py
  • Tests added or updated for changed behavior
  • Documentation and public API examples updated where needed
  • Ruff, mypy, and pytest checks pass

This branch has not been deployed

No deployments
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.

Audio.from_file rejects percent-encoded file URIs from Path.as_uri()

1 participant