test_base.py — langchain Source File
Architecture documentation for test_base.py, a python file in the langchain codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR fe693c2d_3317_b211_b383_2dcf62aeb3ee["test_base.py"] e51e78c8_f355_3edd_309e_1aec4323616a["langchain_core.caches"] fe693c2d_3317_b211_b383_2dcf62aeb3ee --> e51e78c8_f355_3edd_309e_1aec4323616a ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"] fe693c2d_3317_b211_b383_2dcf62aeb3ee --> ac2a9b92_4484_491e_1b48_ec85e71e1d58 aeadc42a_36c1_2b06_1f86_281b6a098beb["langchain_classic.globals"] fe693c2d_3317_b211_b383_2dcf62aeb3ee --> aeadc42a_36c1_2b06_1f86_281b6a098beb c863073e_5563_b09b_4f4e_bc499565aff5["langchain_classic.llms.base"] fe693c2d_3317_b211_b383_2dcf62aeb3ee --> c863073e_5563_b09b_4f4e_bc499565aff5 7e88f5ce_ff41_7d87_8fb2_f355489a149e["tests.unit_tests.llms.fake_llm"] fe693c2d_3317_b211_b383_2dcf62aeb3ee --> 7e88f5ce_ff41_7d87_8fb2_f355489a149e style fe693c2d_3317_b211_b383_2dcf62aeb3ee fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test base LLM functionality."""
from langchain_core.caches import InMemoryCache
from langchain_core.outputs import Generation, LLMResult
from langchain_classic.globals import get_llm_cache, set_llm_cache
from langchain_classic.llms.base import __all__
from tests.unit_tests.llms.fake_llm import FakeLLM
EXPECTED_ALL = [
"BaseLLM",
"LLM",
"BaseLanguageModel",
]
def test_all_imports() -> None:
assert set(__all__) == set(EXPECTED_ALL)
def test_caching() -> None:
"""Test caching behavior."""
set_llm_cache(InMemoryCache())
llm = FakeLLM()
params = llm.dict()
params["stop"] = None
llm_string = str(sorted([(k, v) for k, v in params.items()]))
cache = get_llm_cache()
assert cache is not None
cache.update("foo", llm_string, [Generation(text="fizz")])
output = llm.generate(["foo", "bar", "foo"])
expected_cache_output = [Generation(text="foo")]
cache_output = cache.lookup("bar", llm_string)
assert cache_output == expected_cache_output
set_llm_cache(None)
expected_generations = [
[Generation(text="fizz")],
[Generation(text="foo")],
[Generation(text="fizz")],
]
expected_output = LLMResult(
generations=expected_generations,
llm_output=None,
)
assert output == expected_output
Domain
Subdomains
Functions
Dependencies
- langchain_classic.globals
- langchain_classic.llms.base
- langchain_core.caches
- langchain_core.outputs
- tests.unit_tests.llms.fake_llm
Source
Frequently Asked Questions
What does test_base.py do?
test_base.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_base.py?
test_base.py defines 2 function(s): test_all_imports, test_caching.
What does test_base.py depend on?
test_base.py imports 5 module(s): langchain_classic.globals, langchain_classic.llms.base, langchain_core.caches, langchain_core.outputs, tests.unit_tests.llms.fake_llm.
Where is test_base.py in the architecture?
test_base.py is located at libs/langchain/tests/unit_tests/llms/test_base.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests/llms).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free