Home / Function/ test_rate_limit_invoke() — langchain Function Reference

test_rate_limit_invoke() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  19608031_3ea6_c3cb_fd5d_2bf90951bb16["test_rate_limit_invoke()"]
  fb362766_e486_48d4_95e0_b3a00efb3a56["test_rate_limiting.py"]
  19608031_3ea6_c3cb_fd5d_2bf90951bb16 -->|defined in| fb362766_e486_48d4_95e0_b3a00efb3a56
  style 19608031_3ea6_c3cb_fd5d_2bf90951bb16 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py lines 18–41

def test_rate_limit_invoke() -> 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()
    model.invoke("foo")
    toc = time.time()
    # Should be larger than check every n seconds since the token bucket starts
    # with 0 tokens.
    assert 0.10 < toc - tic < 0.15

    tic = time.time()
    model.invoke("foo")
    toc = time.time()
    # Second time we check the model, we should have 1 extra token
    # since the sleep time is 0.1 seconds
    assert 0.00 < toc - tic < 0.10

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free