Home / Function/ test_rate_limit_ainvoke() — langchain Function Reference

test_rate_limit_ainvoke() — langchain Function Reference

Architecture documentation for the test_rate_limit_ainvoke() function in test_rate_limiting.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8ad140cd_18c3_eb4b_0519_6df9d850a3b7["test_rate_limit_ainvoke()"]
  df01695c_1dbe_973d_756a_a5cd86e49330["test_rate_limiting.py"]
  8ad140cd_18c3_eb4b_0519_6df9d850a3b7 -->|defined in| df01695c_1dbe_973d_756a_a5cd86e49330
  style 8ad140cd_18c3_eb4b_0519_6df9d850a3b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py lines 44–75

async def test_rate_limit_ainvoke() -> None:
    """Add rate limiter."""
    model = GenericFakeChatModel(
        messages=iter(["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
        ),
    )
    tic = time.time()
    await model.ainvoke("foo")
    toc = time.time()
    # Should be larger than check every n seconds since the token bucket starts
    # with 0 tokens.
    assert 0.1 < toc - tic < 0.2

    tic = time.time()
    await model.ainvoke("foo")
    toc = time.time()
    # The second time we call the model, we should have 1 extra token
    # to proceed immediately.
    assert toc - tic < 0.1

    # The third time we call the model, we need to wait again for a token
    tic = time.time()
    await model.ainvoke("foo")
    toc = time.time()
    # Should be larger than check every n seconds since the token bucket starts
    # with 0 tokens.
    assert 0.1 < toc - tic < 0.2

Subdomains

Frequently Asked Questions

What does test_rate_limit_ainvoke() do?
test_rate_limit_ainvoke() 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_ainvoke() defined?
test_rate_limit_ainvoke() is defined in libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py at line 44.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free