Home / File/ cache.py — langchain Source File

cache.py — langchain Source File

Architecture documentation for cache.py, a python file in the langchain codebase. 5 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  92201723_18d0_c857_8abf_4c639e01e4d6["cache.py"]
  cccbe73e_4644_7211_4d55_e8fb133a8014["abc"]
  92201723_18d0_c857_8abf_4c639e01e4d6 --> cccbe73e_4644_7211_4d55_e8fb133a8014
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  92201723_18d0_c857_8abf_4c639e01e4d6 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  e51e78c8_f355_3edd_309e_1aec4323616a["langchain_core.caches"]
  92201723_18d0_c857_8abf_4c639e01e4d6 --> e51e78c8_f355_3edd_309e_1aec4323616a
  ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"]
  92201723_18d0_c857_8abf_4c639e01e4d6 --> ac2a9b92_4484_491e_1b48_ec85e71e1d58
  86e12e47_abd3_7376_ceed_f0108db0965a["langchain_tests.base"]
  92201723_18d0_c857_8abf_4c639e01e4d6 --> 86e12e47_abd3_7376_ceed_f0108db0965a
  style 92201723_18d0_c857_8abf_4c639e01e4d6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Standard tests for the `BaseCache` abstraction.

We don't recommend implementing externally managed `BaseCache` abstractions at this
time.
"""

from abc import abstractmethod

import pytest
from langchain_core.caches import BaseCache
from langchain_core.outputs import Generation

from langchain_tests.base import BaseStandardTests


class SyncCacheTestSuite(BaseStandardTests):
    """Test suite for checking the `BaseCache` API of a caching layer for LLMs.

    This test suite verifies the basic caching API of a caching layer for LLMs.

    The test suite is designed for synchronous caching layers.

    Implementers should subclass this test suite and provide a fixture
    that returns an empty cache for each test.
    """

    @abstractmethod
    @pytest.fixture
    def cache(self) -> BaseCache:
        """Get the cache class to test.

        The returned cache should be EMPTY.
        """

    def get_sample_prompt(self) -> str:
        """Return a sample prompt for testing."""
        return "Sample prompt for testing."

    def get_sample_llm_string(self) -> str:
        """Return a sample LLM string for testing."""
        return "Sample LLM string configuration."

    def get_sample_generation(self) -> Generation:
        """Return a sample `Generation` object for testing."""
        return Generation(
            text="Sample generated text.",
            generation_info={"reason": "test"},
        )

    def test_cache_is_empty(self, cache: BaseCache) -> None:
        """Test that the cache is empty."""
        assert (
            cache.lookup(self.get_sample_prompt(), self.get_sample_llm_string()) is None
        )

    def test_update_cache(self, cache: BaseCache) -> None:
        """Test updating the cache."""
        prompt = self.get_sample_prompt()
        llm_string = self.get_sample_llm_string()
        generation = self.get_sample_generation()
// ... (148 more lines)

Subdomains

Dependencies

  • abc
  • langchain_core.caches
  • langchain_core.outputs
  • langchain_tests.base
  • pytest

Frequently Asked Questions

What does cache.py do?
cache.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What does cache.py depend on?
cache.py imports 5 module(s): abc, langchain_core.caches, langchain_core.outputs, langchain_tests.base, pytest.
Where is cache.py in the architecture?
cache.py is located at libs/standard-tests/langchain_tests/integration_tests/cache.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/standard-tests/langchain_tests/integration_tests).

Analyze Your Own Codebase

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

Try Supermodel Free