Home / File/ base.py — langchain Source File

base.py — langchain Source File

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

File python AgentOrchestration ClassicChains 12 imports 1 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4["base.py"]
  e27da29f_a1f7_49f3_84d5_6be4cb4125c8["logging"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> e27da29f_a1f7_49f3_84d5_6be4cb4125c8
  f3365e3c_fb7a_bb9a_bc79_059b06cb7024["warnings"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> f3365e3c_fb7a_bb9a_bc79_059b06cb7024
  927570d8_11a6_5c17_0f0d_80baae0c733e["pathlib"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 927570d8_11a6_5c17_0f0d_80baae0c733e
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> feec1ec4_6917_867b_d228_b134d0ff8099
  2485b66a_3839_d0b6_ad9c_a4ff40457dc6["langchain_core._api"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 2485b66a_3839_d0b6_ad9c_a4ff40457dc6
  17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 17a62cb3_fefd_6320_b757_b53bb4a1c661
  e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> e929cf21_6ab8_6ff3_3765_0d35a099a053
  4b3dcc0f_d872_0044_39ec_2d289f87f9e6["langchain_core.prompts.prompt"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 4b3dcc0f_d872_0044_39ec_2d289f87f9e6
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> dd5e7909_a646_84f1_497b_cae69735550e
  9a0fc770_8c3f_14bc_3c7d_37852927778e["langchain_classic.chains.base"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 9a0fc770_8c3f_14bc_3c7d_37852927778e
  4044d59c_c0a5_a371_f49b_bea3da4e20ac["langchain_classic.chains.llm"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 4044d59c_c0a5_a371_f49b_bea3da4e20ac
  0bf16f6b_4f46_fb15_0aff_bf2d4f3c153c["langchain_classic.chains.sequential"]
  4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 --> 0bf16f6b_4f46_fb15_0aff_bf2d4f3c153c
  style 4bd52d1b_a9be_e6bd_75e2_1b015e6954f4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Chain for summarization with self-verification."""

from __future__ import annotations

import logging
import warnings
from pathlib import Path
from typing import Any

from langchain_core._api import deprecated
from langchain_core.callbacks import CallbackManagerForChainRun
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts.prompt import PromptTemplate
from pydantic import ConfigDict, model_validator

from langchain_classic.chains.base import Chain
from langchain_classic.chains.llm import LLMChain
from langchain_classic.chains.sequential import SequentialChain

PROMPTS_DIR = Path(__file__).parent / "prompts"
logger = logging.getLogger(__name__)

CREATE_ASSERTIONS_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "create_facts.txt")
CHECK_ASSERTIONS_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "check_facts.txt")
REVISED_SUMMARY_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "revise_summary.txt")
ARE_ALL_TRUE_PROMPT = PromptTemplate.from_file(PROMPTS_DIR / "are_all_true_prompt.txt")


def _load_sequential_chain(
    llm: BaseLanguageModel,
    create_assertions_prompt: PromptTemplate,
    check_assertions_prompt: PromptTemplate,
    revised_summary_prompt: PromptTemplate,
    are_all_true_prompt: PromptTemplate,
    *,
    verbose: bool = False,
) -> SequentialChain:
    return SequentialChain(
        chains=[
            LLMChain(
                llm=llm,
                prompt=create_assertions_prompt,
                output_key="assertions",
                verbose=verbose,
            ),
            LLMChain(
                llm=llm,
                prompt=check_assertions_prompt,
                output_key="checked_assertions",
                verbose=verbose,
            ),
            LLMChain(
                llm=llm,
                prompt=revised_summary_prompt,
                output_key="revised_summary",
                verbose=verbose,
            ),
            LLMChain(
                llm=llm,
                output_key="all_true",
// ... (154 more lines)

Subdomains

Dependencies

  • langchain_classic.chains.base
  • langchain_classic.chains.llm
  • langchain_classic.chains.sequential
  • langchain_core._api
  • langchain_core.callbacks
  • langchain_core.language_models
  • langchain_core.prompts.prompt
  • logging
  • pathlib
  • pydantic
  • typing
  • warnings

Frequently Asked Questions

What does base.py do?
base.py is a source file in the langchain codebase, written in python. It belongs to the AgentOrchestration domain, ClassicChains subdomain.
What functions are defined in base.py?
base.py defines 1 function(s): _load_sequential_chain.
What does base.py depend on?
base.py imports 12 module(s): langchain_classic.chains.base, langchain_classic.chains.llm, langchain_classic.chains.sequential, langchain_core._api, langchain_core.callbacks, langchain_core.language_models, langchain_core.prompts.prompt, logging, and 4 more.
Where is base.py in the architecture?
base.py is located at libs/langchain/langchain_classic/chains/llm_summarization_checker/base.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/chains/llm_summarization_checker).

Analyze Your Own Codebase

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

Try Supermodel Free