Home / Function/ test_rate_limit_skips_cache() — langchain Function Reference

test_rate_limit_skips_cache() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py lines 182–222

def test_rate_limit_skips_cache() -> None:
    """Test that rate limiting does not rate limit cache look ups."""
    cache = InMemoryCache()
    model = GenericFakeChatModel(
        messages=iter(["hello", "world", "!"]),
        rate_limiter=InMemoryRateLimiter(
            requests_per_second=20,
            check_every_n_seconds=0.1,
            max_bucket_size=1,
            # At 20 requests per second we see a refresh every 0.05 seconds
        ),
        cache=cache,
    )

    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.1 < toc - tic < 0.2

    for _ in range(2):
        # Cache hits
        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 toc - tic < 0.05

    # Test verifies that there's only a single key
    # Test also verifies that rate_limiter information is not part of the
    # cache key
    assert list(cache._cache) == [
        (
            '[{"lc": 1, "type": "constructor", "id": ["langchain", "schema", '
            '"messages", "HumanMessage"], "kwargs": {"content": "foo", '
            '"type": "human"}}]',
            "[('_type', 'generic-fake-chat-model'), ('stop', None)]",
        )
    ]

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free