BaseRateLimiter Class — langchain Architecture
Architecture documentation for the BaseRateLimiter class in rate_limiters.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 05335d2f_d103_7c67_8d54_ea059b452805["BaseRateLimiter"] 67db8b02_6e06_ecaf_9ec0_d1db30e3459f["rate_limiters.py"] 05335d2f_d103_7c67_8d54_ea059b452805 -->|defined in| 67db8b02_6e06_ecaf_9ec0_d1db30e3459f 8b0c264d_4f93_5995_59df_1cee2a309abf["acquire()"] 05335d2f_d103_7c67_8d54_ea059b452805 -->|method| 8b0c264d_4f93_5995_59df_1cee2a309abf 21372498_63f5_8ec9_0d35_6d26093dd7ed["aacquire()"] 05335d2f_d103_7c67_8d54_ea059b452805 -->|method| 21372498_63f5_8ec9_0d35_6d26093dd7ed
Relationship Graph
Source Code
libs/core/langchain_core/rate_limiters.py lines 11–64
class BaseRateLimiter(abc.ABC):
"""Base class for rate limiters.
Usage of the base limiter is through the acquire and aacquire methods depending
on whether running in a sync or async context.
Implementations are free to add a timeout parameter to their initialize method
to allow users to specify a timeout for acquiring the necessary tokens when
using a blocking call.
Current limitations:
- Rate limiting information is not surfaced in tracing or callbacks. This means
that the total time it takes to invoke a chat model will encompass both
the time spent waiting for tokens and the time spent making the request.
"""
@abc.abstractmethod
def acquire(self, *, blocking: bool = True) -> bool:
"""Attempt to acquire the necessary tokens for the rate limiter.
This method blocks until the required tokens are available if `blocking`
is set to `True`.
If `blocking` is set to `False`, the method will immediately return the result
of the attempt to acquire the tokens.
Args:
blocking: If `True`, the method will block until the tokens are available.
If `False`, the method will return immediately with the result of
the attempt.
Returns:
`True` if the tokens were successfully acquired, `False` otherwise.
"""
@abc.abstractmethod
async def aacquire(self, *, blocking: bool = True) -> bool:
"""Attempt to acquire the necessary tokens for the rate limiter.
This method blocks until the required tokens are available if `blocking`
is set to `True`.
If `blocking` is set to `False`, the method will immediately return the result
of the attempt to acquire the tokens.
Args:
blocking: If `True`, the method will block until the tokens are available.
If `False`, the method will return immediately with the result of
the attempt.
Returns:
`True` if the tokens were successfully acquired, `False` otherwise.
"""
Defined In
Source
Frequently Asked Questions
What is the BaseRateLimiter class?
BaseRateLimiter is a class in the langchain codebase, defined in libs/core/langchain_core/rate_limiters.py.
Where is BaseRateLimiter defined?
BaseRateLimiter is defined in libs/core/langchain_core/rate_limiters.py at line 11.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free