-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(plugins): Add 20MB file size validation to SaveFilesAsArtifactsPl… #3781
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
base: main
Are you sure you want to change the base?
fix(plugins): Add 20MB file size validation to SaveFilesAsArtifactsPl… #3781
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @AakashSuresh2003, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request effectively addresses the issue of unhandled large file uploads in SaveFilesAsArtifactsPlugin. By introducing a 20MB file size validation, it prevents cryptic errors and provides clear, actionable feedback to the user. The implementation is straightforward, and the accompanying unit tests are comprehensive, covering various edge cases. I have one minor suggestion to improve the maintainability of the error message construction. Overall, this is a great fix.
…ugin with clear error messages and Files API guidance. Fixes google#3751
64a1208 to
85f7c7c
Compare
|
Hi @ryanaiagent, Could you please review my PR and provide any suggestions? |
|
Hi @AakashSuresh2003 I am not sure if we want to impose a 20MB limit, I was looking at this problem and thinking about using google file storage api. I think this would be a better direction if it works! |
|
Sure, Will start working on this direction |
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
The
SaveFilesAsArtifactsPluginfails with a cryptic400 INVALID_ARGUMENTerror when users attempt to upload files larger than approximately 50MB. This error message provides no guidance to users on what went wrong or how to resolve the issue. According to the Gemini API documentation, inline_data uploads have a 20MB size limit, and files larger than this must use the Files API.Solution:
Added file-size routing and validation to automatically handle files of all sizes. The plugin now:
This prevents the cryptic
400 INVALID_ARGUMENTerror from reaching users and provides actionable guidance on how to handle large files properly.Testing Plan
test_file_size_exceeds_limit - Validates that a 50MB file is automatically uploaded via Files API instead of using inline_data
test_file_size_at_limit - Validates that a 20MB file (at the limit) uses inline_data as expected
test_file_size_just_over_limit - Validates that a 21MB file (just over the 20MB limit) is routed to Files API
test_mixed_file_sizes - Validates that multiple files with different sizes (small and large) are handled independently and correctly
test_files_api_upload_failure - Validates graceful error handling when Files API upload fails with proper error messages
test_file_exceeds_files_api_limit - Validates that a 3GB file is rejected with a clear error message about the 2GB limit, and Files API is not called
Unit Tests:
Please include a summary of passed
pytestresults.Manual End-to-End (E2E) Tests:
Created a Python script to test the plugin with different file sizes:
Test Results:
Test 1: Small file upload (5MB)
Result: Clear, actionable error message instead of
400 INVALID_ARGUMENT.Checklist
Additional context
Implementation Details:
_MAX_INLINE_DATA_SIZE_BYTES = 20 * 1024 * 1024(20MB) for inline_data limit_MAX_FILES_API_SIZE_BYTES = 2 * 1024 * 1024 * 1024(2GB) for Files API limitChanges Made:
src/google/adk/plugins/save_files_as_artifacts_plugin.py:tests/unittests/plugins/test_save_files_as_artifacts.py:test_file_size_exceeds_limit- Validates 50MB file uploads via Files APItest_file_size_at_limit- Validates 20MB file uses inline_datatest_file_size_just_over_limit- Validates 21MB file uses Files APItest_mixed_file_sizes- Validates mixed sizes handled independentlytest_files_api_upload_failure- Validates error handling for Files API failurestest_file_exceeds_files_api_limit- Validates 3GB file rejected with 2GB limitReference:
Before this fix:
Users received:
400 INVALID_ARGUMENT: {'error': {'code': 400, 'message': 'Request contains an invalid argument.', 'status': 'INVALID_ARGUMENT'}}After this fix:
[Upload Error: File huge_video.mp4 (3.00 GB) exceeds the maximum supported size of 2GB. Please upload a smaller file.]