langchain.chains.base.Chain¶
class langchain.chains.base.Chain[source]¶
Bases: Serializable, Runnable[Dict[str, Any], Dict[str, Any]], ABC
Abstract base class for creating structured sequences of calls to components.
Chains should be used to encode a sequence of calls to components like
models, document retrievers, other chains, etc., and provide a simple interface
to this sequence.
The Chain interface makes it easy to create apps that are:
Stateful: add Memory to any Chain to give it state,
Observable: pass Callbacks to a Chain to execute additional functionality,like logging, outside the main sequence of component calls,
Composable: the Chain API is flexible enough that it is easy to combineChains with other components, including other Chains.
The main methods exposed by chains are:
__call__: Chains are callable. The __call__ method is the primary way toexecute a Chain. This takes inputs as a dictionary and returns a
dictionary output.
run: A convenience method that takes inputs as args/kwargs and returns theoutput as a string or object. This method can only be used for a subset of
chains and cannot return as rich of an output as __call__.
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
param callback_manager: Optional[langchain.callbacks.base.BaseCallbackManager] = None¶
Deprecated, use callbacks instead.
param callbacks: Optional[Union[List[langchain.callbacks.base.BaseCallbackHandler], langchain.callbacks.base.BaseCallbackManager]] = None¶
Optional list of callback handlers (or callback manager). Defaults to None.
Callback handlers are called throughout the lifecycle of a call to a chain,
starting with on_chain_start, ending with on_chain_end or on_chain_error.