rate_limiters.py — langchain Source File
Architecture documentation for rate_limiters.py, a python file in the langchain codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 572d0e1a_73b6_9fe3_c363_888e67e20392["rate_limiters.py"] cccbe73e_4644_7211_4d55_e8fb133a8014["abc"] 572d0e1a_73b6_9fe3_c363_888e67e20392 --> cccbe73e_4644_7211_4d55_e8fb133a8014 a327e534_84f6_5308_58ca_5727d5eda0cf["asyncio"] 572d0e1a_73b6_9fe3_c363_888e67e20392 --> a327e534_84f6_5308_58ca_5727d5eda0cf 242d0b7d_a8ef_b66d_169b_c791b32a9cc9["threading"] 572d0e1a_73b6_9fe3_c363_888e67e20392 --> 242d0b7d_a8ef_b66d_169b_c791b32a9cc9 0c1d9a1b_c553_0388_dbc1_58af49567aa2["time"] 572d0e1a_73b6_9fe3_c363_888e67e20392 --> 0c1d9a1b_c553_0388_dbc1_58af49567aa2 style 572d0e1a_73b6_9fe3_c363_888e67e20392 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Interface for a rate limiter and an in-memory rate limiter."""
from __future__ import annotations
import abc
import asyncio
import threading
import time
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.
// ... (197 more lines)
Domain
Subdomains
Dependencies
- abc
- asyncio
- threading
- time
Source
Frequently Asked Questions
What does rate_limiters.py do?
rate_limiters.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does rate_limiters.py depend on?
rate_limiters.py imports 4 module(s): abc, asyncio, threading, time.
Where is rate_limiters.py in the architecture?
rate_limiters.py is located at libs/core/langchain_core/rate_limiters.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/langchain_core).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free