test_rate_limit_astream() — langchain Function Reference
Architecture documentation for the test_rate_limit_astream() function in test_rate_limiting.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 1d7d17f0_c2fd_9f76_3559_15b73a491401["test_rate_limit_astream()"] fb362766_e486_48d4_95e0_b3a00efb3a56["test_rate_limiting.py"] 1d7d17f0_c2fd_9f76_3559_15b73a491401 -->|defined in| fb362766_e486_48d4_95e0_b3a00efb3a56 style 1d7d17f0_c2fd_9f76_3559_15b73a491401 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py lines 147–179
async def test_rate_limit_astream() -> None:
"""Test rate limiting astream."""
model = GenericFakeChatModel(
messages=iter(["hello world", "hello world", "hello world"]),
rate_limiter=InMemoryRateLimiter(
requests_per_second=20,
check_every_n_seconds=0.1,
max_bucket_size=10,
# At 20 requests per second we see a refresh every 0.05 seconds
),
)
# Check astream
tic = time.time()
response = [msg async for msg in model.astream("foo")]
assert [msg.content for msg in response] == ["hello", " ", "world"]
toc = time.time()
# Should be larger than check every n seconds since the token bucket starts
assert 0.1 < toc - tic < 0.2
# Second time around we should have 1 token left
tic = time.time()
response = [msg async for msg in model.astream("foo")]
assert [msg.content for msg in response] == ["hello", " ", "world"]
toc = time.time()
# Should be larger than check every n seconds since the token bucket starts
assert toc - tic < 0.1 # Slightly smaller than check every n seconds
# Third time around we should have 0 tokens left
tic = time.time()
response = [msg async for msg in model.astream("foo")]
assert [msg.content for msg in response] == ["hello", " ", "world"]
toc = time.time()
assert 0.1 < toc - tic < 0.2
Domain
Subdomains
Source
Frequently Asked Questions
What does test_rate_limit_astream() do?
test_rate_limit_astream() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py.
Where is test_rate_limit_astream() defined?
test_rate_limit_astream() is defined in libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py at line 147.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free