ConditionalPromptSelector#

class langchain.chains.prompt_selector.ConditionalPromptSelector[source]#

Bases: BasePromptSelector

Prompt collection that goes through conditionals.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param conditionals: List[Tuple[Callable[[BaseLanguageModel], bool], BasePromptTemplate]] [Optional]#

List of conditionals and prompts to use if the conditionals match.

param default_prompt: BasePromptTemplate [Required]#

Default prompt to use if no conditionals match.

get_prompt(llm: BaseLanguageModel) BasePromptTemplate[source]#

Get default prompt for a language model.

Parameters:

llm (BaseLanguageModel) – Language model to get prompt for.

Returns:

Prompt to use for the language model.

Return type:

BasePromptTemplate

Examples using ConditionalPromptSelector