langchain_contrib.prompts.choice package#
Submodules#
langchain_contrib.prompts.choice.prompt_value module#
Module defining prompts involving choices.
- class langchain_contrib.prompts.choice.prompt_value.BaseChoicePrompt(*, prompt: PromptValue, choices: List[str])#
Bases:
PromptValueA prompt that involves picking from a number of choices.
This is just a wrapper around a regular PromptValue that preserves the choice information.
- choices: List[str]#
The list of choices to choose from.
- classmethod from_prompt(prompt: PromptValue, choices: List[str]) BaseChoicePrompt#
Create one of the child classes from a base prompt.
- prompt: PromptValue#
The encapsulated prompt that provides the actual prompt value.
- to_messages() List[BaseMessage]#
Return prompt as messages.
- to_string() str#
Return prompt as string.
- class langchain_contrib.prompts.choice.prompt_value.ChatChoicePrompt(*, messages: List[BaseMessage], prompt: PromptValue, choices: List[str])#
Bases:
BaseChoicePrompt,ChatPromptValueA chat prompt that involves picking from a number of choices.
- to_messages() List[BaseMessage]#
Return prompt as messages.
- to_string() str#
Return prompt as string.
- class langchain_contrib.prompts.choice.prompt_value.ChoiceStr(f_str: F, choices: List[str])#
Bases:
FString that keeps track of choices used to create this string.
- choices: List[str]#
- class langchain_contrib.prompts.choice.prompt_value.StringChoicePrompt(*, text: str, prompt: PromptValue, choices: List[str])#
Bases:
BaseChoicePrompt,StringPromptValueA string prompt that involves picking from a number of choices.
- to_messages() List[BaseMessage]#
Return prompt as messages.
- to_string() str#
Return prompt as string.
langchain_contrib.prompts.choice.template module#
Module that defines the choice prompt.
- class langchain_contrib.prompts.choice.template.ChoicePromptTemplate(*, input_variables: ~typing.List[str], output_parser: ~langchain.schema.output_parser.BaseOutputParser | None = None, partial_variables: ~typing.Mapping[str, str | ~typing.Callable[[], str]] = None, base_template: ~langchain.schema.prompt_template.BasePromptTemplate | None = None, permissive_partial_variables: ~typing.Mapping[str, ~typing.Any] = None, choice_serializer: ~typing.Callable[[~langchain_contrib.prompts.choice.template.T], str] = <function ChoicePromptTemplate.<lambda>>, choices_formatter: ~typing.Callable[[~typing.List[str]], str] = None, choice_format_key: str = 'choices')#
Bases:
ZBasePromptTemplate,Generic[T]A wrapper prompt template for picking from a number of choices.
This template preserves choice information in prompts.
- base_template: BasePromptTemplate | None#
The actual template that this class wraps around.
If None, then this class is assumed to be overridden.
- choice_format_key: str#
Which string is used for formatting choices in the template.
- choice_serializer: Callable[[T], str]#
How to turn the choices into strings.
- choices_formatter: ChoicesFormatter#
How to convert from the list of choices to a single string.
Utility functions to help with this include:
get_simple_joiner
get_oxford_comma_formatter
list_of_choices
- format(**kwargs: Any) str#
Format the prompt with the inputs.
- format_prompt(**kwargs: Any) BaseChoicePrompt#
Format the prompt while preserving the choices.
- classmethod from_base_template(base_template: BasePromptTemplate, **kwargs: Any) ChoicePromptTemplate#
Wrap around a base template.
- classmethod from_messages(messages: Sequence[BaseMessagePromptTemplate | BaseMessage], **kwargs: Any) ChoicePromptTemplate#
Load a ChoicePromptTemplate from message templates.
- classmethod from_template(template: str, **kwargs: Any) ChoicePromptTemplate#
Load a ChoicePromptTemplate from a text template.
- input_variables: List[str]#
A list of the names of the variables the prompt template expects.
- output_parser: BaseOutputParser | None#
How to parse the output of calling an LLM on this formatted prompt.
- partial_variables: Mapping[str, str | Callable[[], str]]#
- permissive_partial(**kwargs: Any) ChoicePromptTemplate#
Return a partial of the prompt template.
Permissive version that allows for arbitrary input types.
- permissive_partial_variables: Mapping[str, Any]#
Partial variables of any type.
The BasePromptTemplate.format and format_prompt functions take in any arbitrary types, so why shouldn’t partials as well?
- langchain_contrib.prompts.choice.template.get_oxford_comma_formatter(conjunction: str = 'or') Callable[[List[str]], str]#
Get a choice formatter that respects the Oxford comma.
- langchain_contrib.prompts.choice.template.get_simple_joiner(joiner: str = ', ') Callable[[List[str]], str]#
Get a choice formatter that’s just a simple joining of strings.
- langchain_contrib.prompts.choice.template.list_of_choices(choices: List[str]) str#
Return a numerical list of choices.
Module contents#
Prompts and templates for choices.
- class langchain_contrib.prompts.choice.BaseChoicePrompt(*, prompt: PromptValue, choices: List[str])#
Bases:
PromptValueA prompt that involves picking from a number of choices.
This is just a wrapper around a regular PromptValue that preserves the choice information.
- choices: List[str]#
The list of choices to choose from.
- classmethod from_prompt(prompt: PromptValue, choices: List[str]) BaseChoicePrompt#
Create one of the child classes from a base prompt.
- prompt: PromptValue#
The encapsulated prompt that provides the actual prompt value.
- to_messages() List[BaseMessage]#
Return prompt as messages.
- to_string() str#
Return prompt as string.
- class langchain_contrib.prompts.choice.ChatChoicePrompt(*, messages: List[BaseMessage], prompt: PromptValue, choices: List[str])#
Bases:
BaseChoicePrompt,ChatPromptValueA chat prompt that involves picking from a number of choices.
- to_messages() List[BaseMessage]#
Return prompt as messages.
- to_string() str#
Return prompt as string.
- class langchain_contrib.prompts.choice.ChoicePromptTemplate(*, input_variables: ~typing.List[str], output_parser: ~langchain.schema.output_parser.BaseOutputParser | None = None, partial_variables: ~typing.Mapping[str, str | ~typing.Callable[[], str]] = None, base_template: ~langchain.schema.prompt_template.BasePromptTemplate | None = None, permissive_partial_variables: ~typing.Mapping[str, ~typing.Any] = None, choice_serializer: ~typing.Callable[[~langchain_contrib.prompts.choice.template.T], str] = <function ChoicePromptTemplate.<lambda>>, choices_formatter: ~typing.Callable[[~typing.List[str]], str] = None, choice_format_key: str = 'choices')#
Bases:
ZBasePromptTemplate,Generic[T]A wrapper prompt template for picking from a number of choices.
This template preserves choice information in prompts.
- base_template: BasePromptTemplate | None#
The actual template that this class wraps around.
If None, then this class is assumed to be overridden.
- choice_format_key: str#
Which string is used for formatting choices in the template.
- choice_serializer: Callable[[T], str]#
How to turn the choices into strings.
- choices_formatter: ChoicesFormatter#
How to convert from the list of choices to a single string.
Utility functions to help with this include:
get_simple_joiner
get_oxford_comma_formatter
list_of_choices
- format(**kwargs: Any) str#
Format the prompt with the inputs.
- format_prompt(**kwargs: Any) BaseChoicePrompt#
Format the prompt while preserving the choices.
- classmethod from_base_template(base_template: BasePromptTemplate, **kwargs: Any) ChoicePromptTemplate#
Wrap around a base template.
- classmethod from_messages(messages: Sequence[BaseMessagePromptTemplate | BaseMessage], **kwargs: Any) ChoicePromptTemplate#
Load a ChoicePromptTemplate from message templates.
- classmethod from_template(template: str, **kwargs: Any) ChoicePromptTemplate#
Load a ChoicePromptTemplate from a text template.
- input_variables: List[str]#
A list of the names of the variables the prompt template expects.
- output_parser: BaseOutputParser | None#
How to parse the output of calling an LLM on this formatted prompt.
- partial_variables: Mapping[str, str | Callable[[], str]]#
- permissive_partial(**kwargs: Any) ChoicePromptTemplate#
Return a partial of the prompt template.
Permissive version that allows for arbitrary input types.
- permissive_partial_variables: Mapping[str, Any]#
Partial variables of any type.
The BasePromptTemplate.format and format_prompt functions take in any arbitrary types, so why shouldn’t partials as well?
- class langchain_contrib.prompts.choice.ChoiceStr(f_str: F, choices: List[str])#
Bases:
FString that keeps track of choices used to create this string.
- choices: List[str]#
- parts: Parts#
- class langchain_contrib.prompts.choice.StringChoicePrompt(*, text: str, prompt: PromptValue, choices: List[str])#
Bases:
BaseChoicePrompt,StringPromptValueA string prompt that involves picking from a number of choices.
- to_messages() List[BaseMessage]#
Return prompt as messages.
- to_string() str#
Return prompt as string.
- langchain_contrib.prompts.choice.get_oxford_comma_formatter(conjunction: str = 'or') Callable[[List[str]], str]#
Get a choice formatter that respects the Oxford comma.
- langchain_contrib.prompts.choice.get_simple_joiner(joiner: str = ', ') Callable[[List[str]], str]#
Get a choice formatter that’s just a simple joining of strings.
- langchain_contrib.prompts.choice.list_of_choices(choices: List[str]) str#
Return a numerical list of choices.