Add Google Gemini support with async processing#29
Conversation
Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
|
You claim that Gemini doesn't have Batch processing. Can you please take a look at https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/batch-prediction-from-cloud-storage#create-batch-job-python_genai_sdk? |
You're absolutely right! I missed that Google now provides batch processing through the
I've implemented true Google Gemini batch processing using the • Real batch processing via Google's batch API instead of async simulation Key commit: Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Look at the openai provider as you need to work like it does, you first need to upload files (if files are supported), and then reference it: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/batch-prediction-from-cloud-storage#create-batch-job-python_genai_sdk |
1 similar comment
|
Look at the openai provider as you need to work like it does, you first need to upload files (if files are supported), and then reference it: https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/batch-prediction-from-cloud-storage#create-batch-job-python_genai_sdk |
Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
Implemented proper file upload pattern following Google's batch API documentation. The Gemini provider now:
This follows the same pattern as the OpenAI provider but adapted for Google's API structure. Commit
Fixed! The Gemini provider now properly uploads files first using Key changes in commit
All tests passing (13/13) with proper batch file handling. |
|
@yammesicka Ready for review :) |
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive Google Gemini support to batchata, implementing Google's native batch API for true batch processing with 50% cost savings. The implementation includes support for 5 Gemini models, structured output with Pydantic models, file processing capabilities, and comprehensive error handling.
Key Changes:
- Added complete Gemini provider with Google's batch API integration
- Implemented support for 5 Gemini models (gemini-2.5-pro, gemini-2.5-flash, etc.)
- Added comprehensive test suite with 51 test cases covering all Gemini functionality
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| batchata/providers/gemini/ | New Gemini provider implementation with batch API support |
| tests/providers/gemini/ | Comprehensive test suite for Gemini provider functionality |
| batchata/providers/provider_registry.py | Registration of Gemini provider in the system |
| batchata/core/job.py | Updated job validation to allow prompt-only jobs |
| pyproject.toml | Added Google dependencies and new example script |
| README.md | Updated documentation with Gemini provider comparison |
| examples/simple_demo.py | Updated demo to use Gemini model |
Comments suppressed due to low confidence (6)
batchata/providers/gemini/models.py:9
- The model version 'gemini-2.5-pro' may not exist. Based on my knowledge cutoff, Google's latest Gemini models were version 1.5. Please verify that version 2.5 models are actually available in the Google API.
"gemini-2.5-pro": ModelConfig(
batchata/providers/gemini/models.py:20
- The model version 'gemini-2.5-flash' may not exist. Based on my knowledge cutoff, Google's latest Gemini models were version 1.5. Please verify that version 2.5 models are actually available in the Google API.
"gemini-2.5-flash": ModelConfig(
batchata/providers/gemini/models.py:31
- The model version 'gemini-2.5-flash-lite' may not exist. Based on my knowledge cutoff, Google's latest Gemini models were version 1.5. Please verify that version 2.5 models are actually available in the Google API.
"gemini-2.5-flash-lite": ModelConfig(
batchata/providers/gemini/models.py:42
- The model version 'gemini-2.0-flash' may not exist. Based on my knowledge cutoff, Google's latest Gemini models were version 1.5. Please verify that version 2.0 models are actually available in the Google API.
"gemini-2.0-flash": ModelConfig(
batchata/providers/gemini/models.py:53
- The model version 'gemini-2.0-flash-lite' may not exist. Based on my knowledge cutoff, Google's latest Gemini models were version 1.5. Please verify that version 2.0 models are actually available in the Google API.
"gemini-2.0-flash-lite": ModelConfig(
tests/providers/gemini/test_models.py:13
- The test asserts that specific model versions exist, but these versions may not be real (based on my knowledge cutoff). This test will fail if the model versions don't actually exist in Google's API.
assert "gemini-2.5-flash" in GEMINI_MODELS
| "pydantic>=2.0", | ||
| "pypdf>=5.8.0", | ||
| "rich>=14.0.0", | ||
| "pytest-asyncio>=1.1.0", |
There was a problem hiding this comment.
The pytest-asyncio dependency is added to the main dependencies but should be in the dev dependencies group since it's only needed for testing.
| "pytest-asyncio>=1.1.0", |
|
|
||
| # Get accurate token count using Google's API | ||
| input_tokens = self._count_tokens(job) | ||
| output_tokens = job.max_tokens or 1000 |
There was a problem hiding this comment.
or 1000? 😂 Should we reconsider this one?
There was a problem hiding this comment.
Replaced the questionable or 1000 fallback with a proper constant FALLBACK_TOKENS_ON_ERROR = 1000 for clarity and maintainability. Commit 5f6ea4e
|
|
||
| model_config = self.get_model_config(job.model) | ||
|
|
||
| if job.file and not model_config.supports_files: |
There was a problem hiding this comment.
This one should probably also validate the filetype(?), or at least throw a warning
There was a problem hiding this comment.
Added file type validation that checks against the model's supported file_types and raises clear validation errors for unsupported formats. Commit 5f6ea4e
| raise ValidationError(f"Model '{job.model}' does not support structured output") | ||
|
|
||
| if job.messages: | ||
| contents, _ = prepare_messages(job) |
There was a problem hiding this comment.
Not a biggie, but we might want to separate preparing the message from this function for purity
There was a problem hiding this comment.
Good point about separating concerns. The message preparation could be extracted to maintain better function purity. For now, keeping it integrated to minimize changes.
| # Handle state by name to avoid enum validation issues | ||
| state_name = getattr(batch_job.state, 'name', str(batch_job.state)) | ||
|
|
||
| if state_name == 'JOB_STATE_SUCCEEDED': |
There was a problem hiding this comment.
Should probably be consts
There was a problem hiding this comment.
Added constants for job states: JOB_STATE_SUCCEEDED, JOB_STATE_FAILED, JOB_STATE_CANCELLED for better maintainability. Commit 5f6ea4e
| if not job_ids: | ||
| return [] | ||
|
|
||
| try: |
There was a problem hiding this comment.
Adding some logs here could be nice
There was a problem hiding this comment.
Agreed! Adding logs for batch status changes, file uploads, and API calls would be very helpful for debugging. This would be a good follow-up improvement.
…ml, improve code quality Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
| IMAGE_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.gif', '.webp'} | ||
| PDF_EXTENSION = '.pdf' | ||
|
|
||
| MIME_TYPE_MAP = { | ||
| '.jpg': 'image/jpeg', | ||
| '.jpeg': 'image/jpeg', | ||
| '.png': 'image/png', | ||
| '.gif': 'image/gif', | ||
| '.webp': 'image/webp', | ||
| '.pdf': 'application/pdf' | ||
| } |
There was a problem hiding this comment.
Consts should be in the start of the file
There was a problem hiding this comment.
Moved constants to the top of the file after imports for better organization. Commit da036aa
…hanism and clear errors Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
Co-authored-by: yammesicka <1492939+yammesicka@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unused pricing constants - Return 0.0 when tokencost unavailable (matches Anthropic behavior) - Add warning log message when tokencost missing - Improve docstring with estimation warnings 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add google-genai>=0.8.0 to dependencies in pyproject.toml - Update uv.lock with new dependency and related packages - Fixes ModuleNotFoundError for google.genai in CI environments - Ensures Gemini provider imports successfully like OpenAI/Anthropic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This PR adds comprehensive support for Google Gemini models to batchata, implementing Google's native batch API for true batch processing with 50% cost savings.
Key Features
🤖 5 Gemini Models Supported
gemini-2.5-flash- High-performance model with fast processinggemini-2.5-pro- Premium model with advanced capabilitiesgemini-1.5-pro- High-performance model with 2M context windowgemini-1.5-flash- Fast model with 1M context windowgemini-1.5-flash-8b- Lightweight version with 1M context⚡ Native Batch Processing
Uses Google's official batch API with inline requests for true batch processing:
🔧 Full Integration
google.genaiSDK with inline batch requests📚 Documentation & Examples
Implementation Details
The Gemini provider implements Google's batch API using:
InlinedRequestformatJOB_STATE_*andBATCH_STATE_*)count_tokensAPI for accurate pricingdest.inlined_responsesTesting
Added comprehensive test suite with 51 test cases covering:
All existing tests continue to pass, ensuring no regression in OpenAI/Anthropic functionality.
Usage
Batch Discount: Gemini provides 50% cost savings through Google's batch API, matching OpenAI and Anthropic batch pricing.
Fixes #6.