Home / Function/ test_rate_limit_stream() — langchain Function Reference

test_rate_limit_stream() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py lines 112–144

def test_rate_limit_stream() -> None:
    """Test rate limit by stream."""
    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 = list(model.stream("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 = list(model.stream("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 = list(model.stream("foo"))
    assert [msg.content for msg in response] == ["hello", " ", "world"]
    toc = time.time()
    assert 0.1 < toc - tic < 0.2

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free