Fix: Handle local file paths in audio content conversion#466
Closed
sidonsoft wants to merge 1 commit intoagentscope-ai:mainfrom
Closed
Fix: Handle local file paths in audio content conversion#466sidonsoft wants to merge 1 commit intoagentscope-ai:mainfrom
sidonsoft wants to merge 1 commit intoagentscope-ai:mainfrom
Conversation
Audio content with local file paths (e.g., /tmp/voice.ogg) were incorrectly wrapped as Base64Source instead of being converted to file:// URLs. Changes: - Add os.path.isfile() check before falling back to base64 - Convert local file paths to file:// URLs using Path.as_uri() - Fix getattr(cnt, 'format') to use default None to prevent AttributeError - Guard media_type construction to avoid 'audio/None' strings Related: agentscope-ai/QwenPaw#1896
|
Russell Stephens seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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
This PR fixes a bug in
message_to_agentscope_msg()where audio content with a local file path (e.g.,/tmp/voice.ogg) would be incorrectly wrapped asBase64Sourceinstead of being converted to a properfile://URL.Related PR: agentscope-ai/QwenPaw#1896
The Bug
In
src/agentscope_runtime/adapters/agentscope/message.py, the audio handling logic has this branching:The problem: Case 3 assumes that non-URL strings are raw base64 data. But if
valueis a local file path like/tmp/voice.ogg:data:URI → skipped Case 1urlparse("/tmp/voice.ogg")givesscheme="",netloc=""→ skipped Case 2The Fix
Added a local file path check using
os.path.isfile()before falling back to base64:Why
os.path.isfile()is AppropriateThe check is strict — it returns
Falseif the file doesn't exist on disk. This is correct because:file://URLs that fail downstream with confusing errorsAdditional Fixes
getattr(cnt, "format")AttributeErrorgetattr(cnt, "format", None)with defaultmedia_type=f"audio/{audio_extension}""audio/None"if format missingNoneif extension missingos.path.isfile()for consistency with CoPawBehavior Changes
/tmp/audio.ogg(existing file)Base64Source(data="/tmp/audio.ogg", media_type="audio/None")❌URLSource(url="file:///tmp/audio.ogg")✅data:audio/ogg;base64,...Base64Source(...)✅https://example.com/audio.oggURLSource(url="...")✅T2dnUw...(raw base64)Base64Source(...)✅Coordination with CoPaw PR
This PR fixes the root cause in agentscope-runtime.
CoPaw PR #1896 adds downstream defensive handling in
message_processing.py. That fix should remain as a safety net for:Both PRs are complementary: