chain.py — langchain Source File
Architecture documentation for chain.py, a python file in the langchain codebase. 12 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR efa3839a_04cc_4e5d_7ba0_06993a200d6c["chain.py"] 2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> 2bf6d401_816d_d011_3b05_a6114f55ff58 feec1ec4_6917_867b_d228_b134d0ff8099["typing"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> feec1ec4_6917_867b_d228_b134d0ff8099 17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> 17a62cb3_fefd_6320_b757_b53bb4a1c661 e929cf21_6ab8_6ff3_3765_0d35a099a053["langchain_core.language_models"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> e929cf21_6ab8_6ff3_3765_0d35a099a053 435e49bf_bb2e_2016_ead7_0afb9d57ad71["langchain_core.prompts"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> 435e49bf_bb2e_2016_ead7_0afb9d57ad71 f40facfc_f3e4_c00f_e491_0760270cea61["langchain_classic.chains.combine_documents.base"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> f40facfc_f3e4_c00f_e491_0760270cea61 a95ae8ee_59d8_73de_6527_20baaa188ab2["langchain_classic.chains.combine_documents.map_reduce"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> a95ae8ee_59d8_73de_6527_20baaa188ab2 187399e0_04c4_3d9d_e228_9285c47b7972["langchain_classic.chains.combine_documents.reduce"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> 187399e0_04c4_3d9d_e228_9285c47b7972 bd39a1d7_82f6_9868_aa1b_9e64bf8d9fcd["langchain_classic.chains.combine_documents.refine"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> bd39a1d7_82f6_9868_aa1b_9e64bf8d9fcd cf026402_2980_66ad_1656_49f205954349["langchain_classic.chains.combine_documents.stuff"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> cf026402_2980_66ad_1656_49f205954349 4044d59c_c0a5_a371_f49b_bea3da4e20ac["langchain_classic.chains.llm"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> 4044d59c_c0a5_a371_f49b_bea3da4e20ac cdde6001_bc39_7408_c905_37b2333f539e["langchain_classic.chains.summarize"] efa3839a_04cc_4e5d_7ba0_06993a200d6c --> cdde6001_bc39_7408_c905_37b2333f539e style efa3839a_04cc_4e5d_7ba0_06993a200d6c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Load summarizing chains."""
from collections.abc import Mapping
from typing import Any, Protocol
from langchain_core.callbacks import Callbacks
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
from langchain_classic.chains.combine_documents.base import BaseCombineDocumentsChain
from langchain_classic.chains.combine_documents.map_reduce import (
MapReduceDocumentsChain,
)
from langchain_classic.chains.combine_documents.reduce import ReduceDocumentsChain
from langchain_classic.chains.combine_documents.refine import RefineDocumentsChain
from langchain_classic.chains.combine_documents.stuff import StuffDocumentsChain
from langchain_classic.chains.llm import LLMChain
from langchain_classic.chains.summarize import (
map_reduce_prompt,
refine_prompts,
stuff_prompt,
)
class LoadingCallable(Protocol):
"""Interface for loading the combine documents chain."""
def __call__(
self,
llm: BaseLanguageModel,
**kwargs: Any,
) -> BaseCombineDocumentsChain:
"""Callable to load the combine documents chain."""
def _load_stuff_chain(
llm: BaseLanguageModel,
*,
prompt: BasePromptTemplate = stuff_prompt.PROMPT,
document_variable_name: str = "text",
verbose: bool | None = None,
**kwargs: Any,
) -> StuffDocumentsChain:
llm_chain = LLMChain(llm=llm, prompt=prompt, verbose=verbose)
"""Load a StuffDocumentsChain for summarization.
Args:
llm: Language Model to use in the chain.
prompt: Prompt template that controls how the documents are formatted and
passed into the LLM.
document_variable_name: Variable name in the prompt template where the
document text will be inserted.
verbose: Whether to log progress and intermediate steps.
**kwargs: Additional keyword arguments passed to the StuffDocumentsChain.
Returns:
A StuffDocumentsChain that takes in documents, formats them with the
given prompt, and runs the chain on the provided LLM.
"""
return StuffDocumentsChain(
// ... (167 more lines)
Domain
Subdomains
Classes
Dependencies
- collections.abc
- langchain_classic.chains.combine_documents.base
- langchain_classic.chains.combine_documents.map_reduce
- langchain_classic.chains.combine_documents.reduce
- langchain_classic.chains.combine_documents.refine
- langchain_classic.chains.combine_documents.stuff
- langchain_classic.chains.llm
- langchain_classic.chains.summarize
- langchain_core.callbacks
- langchain_core.language_models
- langchain_core.prompts
- typing
Source
Frequently Asked Questions
What does chain.py do?
chain.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 chain.py?
chain.py defines 4 function(s): _load_map_reduce_chain, _load_refine_chain, _load_stuff_chain, load_summarize_chain.
What does chain.py depend on?
chain.py imports 12 module(s): collections.abc, langchain_classic.chains.combine_documents.base, langchain_classic.chains.combine_documents.map_reduce, langchain_classic.chains.combine_documents.reduce, langchain_classic.chains.combine_documents.refine, langchain_classic.chains.combine_documents.stuff, langchain_classic.chains.llm, langchain_classic.chains.summarize, and 4 more.
Where is chain.py in the architecture?
chain.py is located at libs/langchain/langchain_classic/chains/summarize/chain.py (domain: AgentOrchestration, subdomain: ClassicChains, directory: libs/langchain/langchain_classic/chains/summarize).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free