Home / File/ test_chain_extract.py — langchain Source File

test_chain_extract.py — langchain Source File

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

File python LangChainCore MessageInterface 3 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  c49efd50_ed8a_1b2b_a881_4d0166e93a94["test_chain_extract.py"]
  6a98b0a5_5607_0043_2e22_a46a464c2d62["langchain_core.documents"]
  c49efd50_ed8a_1b2b_a881_4d0166e93a94 --> 6a98b0a5_5607_0043_2e22_a46a464c2d62
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  c49efd50_ed8a_1b2b_a881_4d0166e93a94 --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  f1384236_4c67_e63a_4b53_42602216421e["langchain_classic.retrievers.document_compressors"]
  c49efd50_ed8a_1b2b_a881_4d0166e93a94 --> f1384236_4c67_e63a_4b53_42602216421e
  style c49efd50_ed8a_1b2b_a881_4d0166e93a94 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from langchain_core.documents import Document
from langchain_core.language_models import FakeListChatModel

from langchain_classic.retrievers.document_compressors import LLMChainExtractor


def test_llm_chain_extractor() -> None:
    documents = [
        Document(
            page_content=(
                "The sky is blue. Candlepin bowling is popular in New England."
            ),
            metadata={"a": 1},
        ),
        Document(
            page_content=(
                "Mercury is the closest planet to the Sun. "
                "Candlepin bowling balls are smaller."
            ),
            metadata={"b": 2},
        ),
        Document(page_content="The moon is round.", metadata={"c": 3}),
    ]
    llm = FakeListChatModel(
        responses=[
            "Candlepin bowling is popular in New England.",
            "Candlepin bowling balls are smaller.",
            "NO_OUTPUT",
        ],
    )
    doc_compressor = LLMChainExtractor.from_llm(llm)
    output = doc_compressor.compress_documents(
        documents,
        "Tell me about Candlepin bowling.",
    )
    expected = documents = [
        Document(
            page_content="Candlepin bowling is popular in New England.",
            metadata={"a": 1},
        ),
        Document(
            page_content="Candlepin bowling balls are smaller.",
            metadata={"b": 2},
        ),
    ]
    assert output == expected


async def test_llm_chain_extractor_async() -> None:
    documents = [
        Document(
            page_content=(
                "The sky is blue. Candlepin bowling is popular in New England."
            ),
            metadata={"a": 1},
        ),
        Document(
            page_content=(
                "Mercury is the closest planet to the Sun. "
                "Candlepin bowling balls are smaller."
            ),
            metadata={"b": 2},
        ),
        Document(page_content="The moon is round.", metadata={"c": 3}),
    ]
    llm = FakeListChatModel(
        responses=[
            "Candlepin bowling is popular in New England.",
            "Candlepin bowling balls are smaller.",
            "NO_OUTPUT",
        ],
    )
    doc_compressor = LLMChainExtractor.from_llm(llm)
    output = await doc_compressor.acompress_documents(
        documents,
        "Tell me about Candlepin bowling.",
    )
    expected = [
        Document(
            page_content="Candlepin bowling is popular in New England.",
            metadata={"a": 1},
        ),
        Document(
            page_content="Candlepin bowling balls are smaller.",
            metadata={"b": 2},
        ),
    ]
    assert output == expected

Domain

Subdomains

Dependencies

  • langchain_classic.retrievers.document_compressors
  • langchain_core.documents
  • langchain_core.language_models

Frequently Asked Questions

What does test_chain_extract.py do?
test_chain_extract.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What functions are defined in test_chain_extract.py?
test_chain_extract.py defines 2 function(s): test_llm_chain_extractor, test_llm_chain_extractor_async.
What does test_chain_extract.py depend on?
test_chain_extract.py imports 3 module(s): langchain_classic.retrievers.document_compressors, langchain_core.documents, langchain_core.language_models.
Where is test_chain_extract.py in the architecture?
test_chain_extract.py is located at libs/langchain/tests/unit_tests/retrievers/document_compressors/test_chain_extract.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain/tests/unit_tests/retrievers/document_compressors).

Analyze Your Own Codebase

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

Try Supermodel Free