BaseRateLimiter#
- class langchain_core.rate_limiters.BaseRateLimiter(*args, **kwargs)[source]#
Beta
Introduced in 0.2.24. API subject to change.
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.
New in version 0.2.24.
Methods
__init__
(*args, **kwargs)aacquire
(*[, blocking])Attempt to acquire the necessary tokens for the rate limiter.
acquire
(*[, blocking])Attempt to acquire the necessary tokens for the rate limiter.
- __init__(*args: Any, **kwargs: Any) Any #
- Parameters:
self (Any) –
args (Any) –
kwargs (Any) –
- Return type:
Any
- abstract async aacquire(*, blocking: bool = True) bool [source]#
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.
- Parameters:
blocking (bool) – If True, the method will block until the tokens are available. If False, the method will return immediately with the result of the attempt. Defaults to True.
- Returns:
True if the tokens were successfully acquired, False otherwise.
- Return type:
bool
- abstract acquire(*, blocking: bool = True) bool [source]#
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.
- Parameters:
blocking (bool) – If True, the method will block until the tokens are available. If False, the method will return immediately with the result of the attempt. Defaults to True.
- Returns:
True if the tokens were successfully acquired, False otherwise.
- Return type:
bool