fix(audio): derive transcription filename with os.path.basename - #32617
fix(audio): derive transcription filename with os.path.basename#32617anxkhn wants to merge 1 commit into
Conversation
process_audio_file derived the multipart filename from a PathLike input
with file_path.split("/")[-1]. On Windows, str(Path('C:/dir/name.mp3'))
is 'C:\\dir\\name.mp3', which contains no forward slash, so the split
returned the entire path (drive letter and backslashes) instead of the
basename. That full path was then sent to provider transcription APIs as
the form-data file name.
Use os.path.basename, matching the sibling PathLike file-input sink in
ocr/main.py. Add a regression test that patches os.path to ntpath to
reproduce Windows semantics on any host.
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
|
|
Greptile SummaryReplaces a POSIX-only
Confidence Score: 5/5Minimal, targeted fix with no side-effects on other paths; safe to merge. The change touches a single line inside a well-isolated branch of No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/litellm_core_utils/audio_utils/utils.py | Single-line correctness fix: replaces file_path.split("/")[-1] with os.path.basename(file_path) so Windows paths are correctly parsed; os was already imported. |
| tests/test_litellm/litellm_core_utils/test_audio_utils.py | Adds test_process_windows_pathlib_input_basename, a mock-only regression test that patches os.path to ntpath and open to reproduce Windows path semantics on any CI host, confirming the basename fix is correct. |
Reviews (1): Last reviewed commit: "fix(audio): derive transcription filenam..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@yucheng-berri when you have a chance, could you please take a look at this pr and let me know if any update is needed? |
Relevant issues
No existing issue. This is a small correctness fix found while reading the
file-input hardening added in #27762.
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
process_audio_filebuilds the multipart file name that is sent to providertranscription APIs. For a
PathLikeinput on Windows the file name was thewhole path instead of the base name. The added regression test reproduces
Windows path semantics on any host by pointing the module's
os.pathatntpath:Before the fix (old
file_path.split("/")[-1]):After the fix (
os.path.basename(file_path)):Type
🐛 Bug Fix
Changes
process_audio_file(inlitellm/litellm_core_utils/audio_utils/utils.py)derived the multipart file name from a
PathLikeinput withfilename = file_path.split("/")[-1], wherefile_path = str(audio_file).That split assumes a POSIX separator. On Windows,
str(Path("C:/dir/name.mp3"))is"C:\\dir\\name.mp3", which contains noforward slash, so
split("/")[-1]returns the entire path (drive letter andbackslashes) rather than the base name. The full path then reaches provider
transcription requests as the form-data file part name (for example the
files={"file": (filename, content, content_type)}payload built by themistral, soniox, azure, deepgram and other transcription transformers that call
process_audio_file).The fix uses
os.path.basename(file_path), which extracts the base namecorrectly on each OS because
str(PathLike)andos.pathuse the sameseparator for the host. This matches the sibling
PathLikefile-input sink inlitellm/ocr/main.py, which was hardened alongside this code in #27762.A regression test (
test_process_windows_pathlib_input_basename) was added tothe existing mapped test file. It patches the module's
os.pathtontpathand feeds a
PureWindowsPath, so it reproduces Windows behavior on the POSIX CIhost: it fails on the old split (the full path leaks) and passes on the fix.
Diff (2 files, +30 / -1)
Plus the new test
test_process_windows_pathlib_input_basenameintests/test_litellm/litellm_core_utils/test_audio_utils.py.