Home / File/ test_flare.py — langchain Source File

test_flare.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 7 imports 2 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4["test_flare.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  38bc5323_3713_7377_32f8_091293bea54b["langchain_core.retrievers"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> 38bc5323_3713_7377_32f8_091293bea54b
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  bcf0614e_f942_865c_7318_0a87c8f4d3bc["langchain_classic.chains.flare.base"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> bcf0614e_f942_865c_7318_0a87c8f4d3bc
  0b28cff6_d823_1571_d2bb_ec61508cc89c["langchain_openai"]
  49f8dcbd_53e1_0563_3ec3_27cb131d0af4 --> 0b28cff6_d823_1571_d2bb_ec61508cc89c
  style 49f8dcbd_53e1_0563_3ec3_27cb131d0af4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Tests for FlareChain.from_llm preserving supplied ChatOpenAI instance."""

from typing import cast

import pytest
from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langchain_core.runnables import RunnableSequence

from langchain_classic.chains.flare.base import FlareChain


class _EmptyRetriever(BaseRetriever):
    """Minimal no-op retriever used only for constructing FlareChain in tests."""

    def _get_relevant_documents(self, query: str) -> list[Document]:  # type: ignore[override]
        del query  # mark used
        return []

    async def _aget_relevant_documents(self, query: str) -> list[Document]:  # type: ignore[override]
        del query  # mark used
        return []


def test_from_llm_rejects_non_chatopenai() -> None:
    class Dummy:
        pass

    with pytest.raises(TypeError):
        FlareChain.from_llm(Dummy())  # type: ignore[arg-type]


@pytest.mark.requires("langchain_openai")
def test_from_llm_uses_supplied_chatopenai(monkeypatch: pytest.MonkeyPatch) -> None:
    try:
        from langchain_openai import ChatOpenAI
    except ImportError:  # pragma: no cover
        pytest.skip("langchain-openai not installed")

    # Provide dummy API key to satisfy constructor env validation.
    monkeypatch.setenv("OPENAI_API_KEY", "TEST")

    supplied = ChatOpenAI(temperature=0.51, logprobs=True, max_completion_tokens=21)
    chain = FlareChain.from_llm(
        supplied,
        max_generation_len=32,
        retriever=_EmptyRetriever(),
    )

    llm_in_chain = cast("RunnableSequence", chain.question_generator_chain).steps[1]
    assert llm_in_chain is supplied

Subdomains

Dependencies

  • langchain_classic.chains.flare.base
  • langchain_core.documents
  • langchain_core.retrievers
  • langchain_core.runnables
  • langchain_openai
  • pytest
  • typing

Frequently Asked Questions

What does test_flare.py do?
test_flare.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_flare.py?
test_flare.py defines 2 function(s): test_from_llm_rejects_non_chatopenai, test_from_llm_uses_supplied_chatopenai.
What does test_flare.py depend on?
test_flare.py imports 7 module(s): langchain_classic.chains.flare.base, langchain_core.documents, langchain_core.retrievers, langchain_core.runnables, langchain_openai, pytest, typing.
Where is test_flare.py in the architecture?
test_flare.py is located at libs/langchain/tests/unit_tests/chains/test_flare.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/tests/unit_tests/chains).

Analyze Your Own Codebase

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

Try Supermodel Free