langchain_contrib.prompts package#

Subpackages#

Submodules#

langchain_contrib.prompts.chained module#

Defines the Chained prompt template type.

class langchain_contrib.prompts.chained.ChainedPromptTemplate(subprompts: List[str | BaseMessagePromptTemplate | BaseMessage | BasePromptTemplate], joiner: str = '', *, input_variables: List[str], output_parser: BaseOutputParser | None = None, partial_variables: Mapping[str, str | Callable[[], str]] = None)#

Bases: StringPromptTemplate

A prompt template composed of multiple other prompt templates chained together.

This is a StringPromptTemplate rather than a BasePromptTemplate to enable use in BaseStringMessagePromptTemplate.

format(**kwargs: Any) str#

Format the prompt with the inputs.

format_prompt(**kwargs: Any) PromptValue#

Format each series of prompts with the given inputs.

joiner: str#

How to join each template output together.

Only meaningful for StringPromptTemplate’s.

subprompts: List[BasePromptTemplate]#

langchain_contrib.prompts.prefixed module#

Defines the Prefixed prompt template type.

class langchain_contrib.prompts.prefixed.PrefixedTemplate(templatable: Templatable)#

Bases: BaseModel

Wraps another prompt template into one that can take in a prefix.

This is useful for when you want to add a prefix to a prompt, but you don’t want to have to do it manually.

class Config#

Bases: object

Configuration for this pydantic object.

extra = 'forbid'#
template: BasePromptTemplate#

langchain_contrib.prompts.schema module#

Types useful for prompting.

langchain_contrib.prompts.schema.Templatable#

Anything that can be converted directly into a BasePromptTemplate.

alias of Union[str, BaseMessagePromptTemplate, BaseMessage, BasePromptTemplate]

langchain_contrib.prompts.schema.into_template(templatable: str | BaseMessagePromptTemplate | BaseMessage | BasePromptTemplate) BasePromptTemplate#

Convert a Templatable into a proper BasePromptTemplate.

Module contents#

Experimental LLM chains.

class langchain_contrib.prompts.ChainedPromptTemplate(subprompts: List[str | BaseMessagePromptTemplate | BaseMessage | BasePromptTemplate], joiner: str = '', *, input_variables: List[str], output_parser: BaseOutputParser | None = None, partial_variables: Mapping[str, str | Callable[[], str]] = None)#

Bases: StringPromptTemplate

A prompt template composed of multiple other prompt templates chained together.

This is a StringPromptTemplate rather than a BasePromptTemplate to enable use in BaseStringMessagePromptTemplate.

format(**kwargs: Any) str#

Format the prompt with the inputs.

format_prompt(**kwargs: Any) PromptValue#

Format each series of prompts with the given inputs.

input_variables: List[str]#

A list of the names of the variables the prompt template expects.

joiner: str#

How to join each template output together.

Only meaningful for StringPromptTemplate’s.

output_parser: BaseOutputParser | None#

How to parse the output of calling an LLM on this formatted prompt.

partial_variables: Mapping[str, str | Callable[[], str]]#
subprompts: List[BasePromptTemplate]#
class langchain_contrib.prompts.ChoicePromptTemplate(*, input_variables: List[str], output_parser: BaseOutputParser | None = None, partial_variables: Mapping[str, str | Callable[[], str]] = None, base_template: BasePromptTemplate, choices: List[str], choices_formatter: Callable[[List[str]], str] = None, choice_format_key: str = 'choices')#

Bases: BasePromptTemplate

A wrapper prompt template for picking from a number of choices.

This template preserves choice information in prompts.

base_template: BasePromptTemplate#

The base template that this class wraps around.

choice_format_key: str#

Which string is used for formatting choices in the template.

choices: List[str]#

The list of choices to pick from.

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, choices: List[str], **kwargs: Any) ChoicePromptTemplate#

Load a ChoicePromptTemplate from base templates.

classmethod from_messages(messages: Sequence[BaseMessagePromptTemplate | BaseMessage], choices: List[str], **kwargs: Any) ChoicePromptTemplate#

Load a ChoicePromptTemplate from message templates.

classmethod from_template(template: str, choices: List[str], **kwargs: Any) ChoicePromptTemplate#

Load a ChoicePromptTemplate from a text template.

class langchain_contrib.prompts.PrefixedTemplate(templatable: Templatable)#

Bases: BaseModel

Wraps another prompt template into one that can take in a prefix.

This is useful for when you want to add a prefix to a prompt, but you don’t want to have to do it manually.

class Config#

Bases: object

Configuration for this pydantic object.

extra = 'forbid'#
template: BasePromptTemplate#
langchain_contrib.prompts.into_template(templatable: str | BaseMessagePromptTemplate | BaseMessage | BasePromptTemplate) BasePromptTemplate#

Convert a Templatable into a proper BasePromptTemplate.