-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Error 500 on multimodal input with empty base64 image data #3241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds validation to prevent empty base64 data from causing issues in image processing. When base64:// prefixes are removed but leave empty strings, the code now properly detects and handles these cases.
Key changes:
- Added empty base64 data validation checks across image and record handling methods
- Added error handling in LLM request processing to gracefully skip invalid images
- Enhanced error messages to include context about which image/record failed
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
astrbot/core/message/components.py |
Added empty base64 validation checks in Record and Image classes' convert_to_file_path() and convert_to_base64() methods |
astrbot/core/pipeline/process_stage/method/llm_request.py |
Wrapped image path conversion in try-except to gracefully handle ValueError from invalid images |
astrbot/core/provider/sources/openai_source.py |
Added empty base64 validation in encode_image_bs64() method with warning log and early return |
| bs64_data = bs64_data.removeprefix("base64://") | ||
| if not bs64_data: | ||
| raise ValueError(f"Base64 data is empty for image: {url}") |
Copilot
AI
Nov 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file_to_base64() function always returns strings prefixed with "base64://", so after removing the prefix on line 482, bs64_data can never be empty (it will always contain the base64-encoded content). This validation check is unreachable and will never trigger. The validation should occur before calling file_to_base64() or should validate the actual data content length.
Co-authored-by: LIghtJUNction <106986785+LIghtJUNction@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
QQ platform occasionally sends image messages with
file: "base64://"containing no actual base64 data. The bot would decode this empty string, create a 0-byte file, re-encode it as empty base64, and senddata:image/jpeg;base64,to the LLM API, causing Error 500: "base64 string is empty".Changes
Validation at decode points
Image.convert_to_file_path()andconvert_to_base64(): RaiseValueErrorif base64 data is empty after prefix removalRecord: Same validation for consistencyopenai_source.encode_image_bs64(): Return empty string with warning for empty base64Error handling
llm_request.py: CatchValueErrorfromconvert_to_file_path(), log warning, skip invalid imagesExample flow
Fixes #3239
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.soulter.top/home/REDACTED/work/AstrBot/AstrBot/.venv/bin/python /home/REDACTED/work/AstrBot/AstrBot/.venv/bin/pytest tests/ -v(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.