Update Tool Server#37
Merged
Merged
Conversation
- Updated the search function to include an authenticator dependency for managing API key usage. - Implemented error handling to roll back usage reservations in case of request failures. - Added a new method in APIKeyAuthenticator to decrement usage counters, ensuring accurate tracking of API key usage.
- Introduced new environment variables for API key usage retries and delays. - Implemented a retry mechanism with exponential backoff for Firestore transactions in the API key repository. - Added a method to decrement the usage counter, ensuring accurate tracking during request failures.
- Introduced DailyUsageRepository to manage daily usage counters. - Added environment variables for daily usage configuration in .env.example and README. - Updated app.py to integrate daily usage tracking with API key consumption. - Modified Dockerfile to include daily_usage.py. - Enhanced tests to validate usage consumption and limits.
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a dual-tier usage tracking system for Gemini grounding requests, implementing daily free-tier allowances alongside existing API key quotas. The implementation includes rollback mechanisms for failed requests and retry logic for transactional updates.
- Adds daily usage counters with configurable free limits per model/bucket
- Implements usage reservation rollback for both daily and API key quotas when requests fail
- Adds retry logic with exponential backoff for Firestore transaction conflicts
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/web_search/daily_usage.py | New repository implementing daily usage counters with reserve/release operations |
| src/utils/web_search/db.py | Added decrement_usage_counter method with retry logic for API key usage rollback |
| src/utils/web_search/auth.py | Added consume_usage and release_usage methods for deferred and rollback usage accounting |
| src/utils/web_search/app.py | Integrated daily usage tracking into request flow with two-phase commit pattern |
| tests/test_web_search_auth.py | Added test coverage for new release_usage and consume_usage methods |
| src/utils/web_search/README.md | Documented new environment variables for daily usage configuration |
| src/utils/web_search/.env.example | Added configuration examples for daily usage limits and retry tuning |
| src/utils/web_search/Dockerfile | Updated to include daily_usage.py in container |
| src/utils/web_search/.dockerignore | Updated to exclude daily_usage.py from ignore list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
PR Type
Fix, Feature
Short Description
Tests Added
...