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.BaseMemory | None = None, callback_manager: ~langchain.callbacks.base.BaseCallbackManager = None, verbose: bool = 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] = [])#

Bases: Chain, BaseModel, ABC

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

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.

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.testing module#

Fake chains for testing purposes.

class langchain_contrib.chains.testing.FakeChain(*, memory: BaseMemory | None = None, callback_manager: BaseCallbackManager = None, verbose: bool = None, expected_inputs: List[str] = [], expected_outputs: List[str] = [], output: Dict[str, str] = {}, inputs_to_outputs: Callable[[Dict[str, str]], Dict[str, str]] | None = None)#

Bases: Chain

Fake chain that returns predefined outputs.

class Config#

Bases: object

Configuration for this pydantic object.

extra = 'forbid'#
expected_inputs: List[str]#

List of input keys to expect.

expected_outputs: List[str]#

List of output keys to expect.

Not needed if output is defined.

property input_keys: List[str]#

Input keys this chain expects.

inputs_to_outputs: Callable[[Dict[str, str]], Dict[str, str]] | None#

Function to transform inputs to outputs.

output: Dict[str, str]#

The dict to return when this chain is called.

This is ignored if inputs_to_outputs is defined.

property output_keys: List[str]#

The keys of the predefined output dict.

langchain_contrib.chains.tool module#

Module that defines a Chain wrapper for Tools.

class langchain_contrib.chains.tool.ToolChain(*, memory: BaseMemory | None = None, callback_manager: BaseCallbackManager = None, verbose: bool = 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#

Experimental LLM chains.

class langchain_contrib.chains.ChoiceChain(*, memory: ~langchain.schema.BaseMemory | None = None, callback_manager: ~langchain.callbacks.base.BaseCallbackManager = None, verbose: bool = 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] = [])#

Bases: Chain, BaseModel, ABC

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

callback_manager: BaseCallbackManager#
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.

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.

memory: BaseMemory | None#
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.

verbose: bool#
class langchain_contrib.chains.ToolChain(*, memory: BaseMemory | None = None, callback_manager: BaseCallbackManager = None, verbose: bool = 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.

callback_manager: BaseCallbackManager#
property input_keys: List[str]#

Input keys this chain expects.

memory: BaseMemory | None#
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.

verbose: bool#