langchain_contrib.chains package#

Subpackages#

Submodules#

langchain_contrib.chains.choice module#

Chain that chooses and performs the next action.

class langchain_contrib.chains.choice.ChoiceChain(*, memory: ~langchain.schema.memory.BaseMemory | None = None, callbacks: ~typing.List[~langchain.callbacks.base.BaseCallbackHandler] | ~langchain.callbacks.base.BaseCallbackManager | None = None, callback_manager: ~langchain.callbacks.base.BaseCallbackManager | None = None, verbose: bool = None, tags: ~typing.List[str] | None = None, metadata: ~typing.Dict[str, ~typing.Any] | None = None, choice_picker: ~langchain.chains.base.Chain, prep_picker_output: ~typing.Callable[[~typing.Dict[str, str]], ~typing.Dict[str, str]] = <function ChoiceChain.<lambda>>, choices: ~typing.Mapping[str, ~langchain.chains.base.Chain], choice_key: str = 'choice', ignore_keys: ~typing.List[str] = [], emit_io_info: bool = False, chain_inputs_key: str = 'choice_inputs', chain_outputs_key: str = 'choice_outputs')#

Bases: Chain

Chain that asks the LLM for a decision and executes it.

chain_inputs_key: str#

Key for chosen chain inputs.

chain_outputs_key: str#

Key for chosen chain outputs.

choice_key: str#

choice_picker output key that tells us which choice was picked.

choice_picker: Chain#

The chain that actually prompts the LLM for the choice.

choices: Mapping[str, Chain]#

The chains that will be run depending on the LLM’s choice.

This is a mapping from which LLM output corresponds to which chain.

chosen_inputs(outputs: Dict[str, str]) Dict[str, str]#

Extract the inputs to the chosen chain from ChoiceChain output.

chosen_outputs(outputs: Dict[str, str]) Dict[str, str]#

Extract the outputs from the chosen chain from ChoiceChain output.

emit_io_info: bool#

If true, also returns input and output dicts for the chosen chain.

Outputs will be returned in JSON form to preserve string function signatures.

classmethod from_tools(choice_picker: Chain, tools: List[BaseTool], excluded_colors: List[str] = ['green'], verbose: bool = False, **kwargs: Any) ChoiceChain#

Construct a ChoiceChain from tools.

This also assigns colors to each tool.

ignore_keys: List[str]#

Keys that will be returned in final output, but not passed on to chosen chain.

property input_keys: List[str]#

Input keys to this chain.

property output_keys: List[str]#

Possible output keys produced by this chain.

prep_picker_output: Callable[[Dict[str, str]], Dict[str, str]]#

Interprets output from the picker chain for the chosen chain.

Override this to do additional dict munging before it gets passed through to the chosen chain.

langchain_contrib.chains.dummy module#

langchain_contrib.chains.testing module#

langchain_contrib.chains.tool module#

Module that defines a Chain wrapper for Tools.

class langchain_contrib.chains.tool.ToolChain(*, memory: BaseMemory | None = None, callbacks: List[BaseCallbackHandler] | BaseCallbackManager | None = None, callback_manager: BaseCallbackManager | None = None, verbose: bool = None, tags: List[str] | None = None, metadata: Dict[str, Any] | None = None, tool: BaseTool, tool_input_key: str = 'action_input', tool_output_key: str = 'action_result')#

Bases: Chain

Wraps a Tool in a Chain.

Allows for tool and chain interop outside of the Agent class.

property input_keys: List[str]#

Input keys this chain expects.

property output_keys: List[str]#

Output keys this chain expects.

tool: BaseTool#

The tool this chain will call when invoked.

tool_input_key: str#

The key for this class to feed into the tool.

tool_output_key: str#

The key produced by this class as a result of using the tool.

Module contents#