simple_chain_builder
Single-step chain builder module
Attributes
Classes
SimpleChainBuilder
Bases: BaseChainBuilder
Attributes
chain_param_overrides
class-attribute
instance-attribute
chain_param_overrides: Dict[str, Dict] = Field(
default_factory=dict,
title="Chain Parameter Overrides",
description="",
)
chain_params
class-attribute
instance-attribute
chain_params: Dict[str, Any] = Field(
...,
title="Chain Parameters",
description="Contains parameters that are passed to the chain builder and are lazily evaluated when the chain is loaded. The key in this dictionary is used for matching LLM names such that specific parameter overrides can be configured per LLM.",
)
llm_ref
class-attribute
instance-attribute
llm_ref: str | None = Field(
default=None,
title="LLM Reference",
description="Reference to the chain LLM",
)
Functions
base_chain
base_chain(
llm_metadata: Dict[str, Any] | None = None
) -> Tuple[
SimpleChainBuilderParams,
RunnableSerializable,
Dict[str, RunnableLambda],
]
Creates the base chain components
build
Builds the chain configuration.
This method is responsible for building the chain configuration based on the parameters provided in the configuration.
Returns:
-
RunnableSerializable
(RunnableSerializable
) –The chain configuration
derive_chain_params
derive_chain_params(
llm_ref: str | None,
) -> SimpleChainBuilderParams
Get the LLM parameters based on the llm_ref.
Parameters:
-
llm_ref
(str | None
) –The reference to the LLM parameters.
Returns:
-
P
(SimpleChainBuilderParams
) –The merged LLM parameters.
Raises:
-
ValueError
–If no LLM parameters are found for the given llm_ref and no defaults are configured on the chain.
derive_chain_token_limits
derive_chain_token_limits(
base_template: Dict[str, Any] | None = None,
default_output_token_pct: float = 0.25,
) -> Tuple[int, int, BaseTokenizer]
Derives the token limits for a given chain.
Intended use case is for routines that will be stuffing data into a language model and need to know the maximum input and output token limits.
Example usage:
max_input_tokens, max_output_tokens, tokenizer = derive_chain_token_limits( chain_name=”cognitive_derive_values” )
Parameters:
-
base_template
(Dict[str, Any]
, default:None
) –The base template for the prompt. Defaults to None.
-
default_output_token_pct
(float
, default:0.25
) –The default percentage of output tokens. Defaults to 0.25.
Returns:
-
Tuple[int, int, BaseTokenizer]
–Tuple[int, int, BaseTokenizer]: A tuple containing the maximum input tokens, maximum output tokens, and the tokenizer.
Raises:
-
ValueError
–If the chain factory is not found.
SimpleChainBuilderParams
Bases: BaseModel
Simple chain builder parameters object
Attributes
additional_echo_fields
class-attribute
instance-attribute
additional_echo_fields: List[str] | None = Field(
default=None,
title="Additional Echo Fields",
description="",
)
llm_bind_kwargs
class-attribute
instance-attribute
llm_bind_kwargs: Dict[str, Any] = Field(
default_factory=dict,
title="LLM Bind Kwargs",
description="",
)
mapper_to_str_kwargs
class-attribute
instance-attribute
mapper_to_str_kwargs: Dict[str, Any] = Field(
default_factory=dict,
title="Mapper to Str Kwargs",
description="",
)
model_config
class-attribute
instance-attribute
model_config = ConfigDict(
populate_by_name=True,
use_enum_values=False,
extra="forbid",
strict=False,
arbitrary_types_allowed=True,
)
output_parser
class-attribute
instance-attribute
output_parser: Any = Field(
default=None,
title="Output Parser",
description="Optional Langchain output parser",
)
response_field_name
class-attribute
instance-attribute
response_field_name: str = Field(
default=FIELD_RESPONSE,
title="Response Field Name",
description="Name of the field in the response that contains the output",
)