Skip to content

Conversation

@sobithav18
Copy link

@sobithav18 sobithav18 commented Oct 10, 2025

#issue 13, hacktoberfest
This PR adds a thread-safe, configurable rate limiter to ChatGradient to prevent 429 errors during rapid API calls. It uses a token bucket algorithm with a sliding window and supports concurrent requests. The feature is opt-in, fully backwards compatible, and includes unit and integration tests. Users can set custom limits, monitor usage, and handle bursts efficiently. All tests pass locally, and the implementation has no external dependencies. Maintainers with API access are asked to verify real-world behavior.

@bnarasimha21 bnarasimha21 requested a review from Copilot October 28, 2025 12:59
Copy link

Copilot AI left a 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 production-grade rate limiting to the ChatGradient client to prevent 429 API throttling errors. The implementation uses a thread-safe token bucket algorithm with a sliding window and is fully backwards compatible (opt-in feature).

Key Changes:

  • New RateLimiter class with sliding window token bucket algorithm
  • Integration with ChatGradient via enable_rate_limiting and max_requests_per_minute parameters
  • Comprehensive test coverage for unit, integration, and real-world scenarios

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
langchain_gradient/rate_limiter.py New rate limiter implementation with thread-safe token bucket algorithm
langchain_gradient/chat_models.py Integration of rate limiting into ChatGradient's _generate and _stream methods
langchain_gradient/constants.py Added rate limiting parameters to allowed model fields
tests/unit_tests/test_rate_limiter.py Unit tests for RateLimiter class
tests/unit_tests/test_chat_models_with_rate_limiting.py Unit tests for ChatGradient rate limiting integration
tests/integration_tests/test_rate_limiting.py Integration tests for rate limiter
tests/integration_tests/test_chat_models*.py Code formatting improvements (import reordering, trailing comma fixes)
pyproject.toml Added pytest to dev dependencies
examples/rate_limiting_demo.py Comprehensive demonstration of rate limiting features

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sobithav18 and others added 2 commits October 28, 2025 18:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant