[docs]classBaseMessagePromptTemplate(Serializable,ABC):"""Base class for message prompt templates."""@classmethoddefis_lc_serializable(cls)->bool:"""Return whether or not the class is serializable. Returns: True. """returnTrue@classmethoddefget_lc_namespace(cls)->list[str]:"""Get the namespace of the langchain object. Default namespace is ["langchain", "prompts", "chat"]. """return["langchain","prompts","chat"]
[docs]@abstractmethoddefformat_messages(self,**kwargs:Any)->list[BaseMessage]:"""Format messages from kwargs. Should return a list of BaseMessages. Args: **kwargs: Keyword arguments to use for formatting. Returns: List of BaseMessages. """
[docs]asyncdefaformat_messages(self,**kwargs:Any)->list[BaseMessage]:"""Async format messages from kwargs. Args: **kwargs: Keyword arguments to use for formatting. Returns: List of BaseMessages. """returnself.format_messages(**kwargs)
@property@abstractmethoddefinput_variables(self)->list[str]:"""Input variables for this prompt template. Returns: List of input variables. """
[docs]defpretty_repr(self,html:bool=False,# noqa: FBT001,FBT002)->str:"""Human-readable representation. Args: html: Whether to format as HTML. Defaults to False. Returns: Human-readable representation. """raiseNotImplementedError
[docs]defpretty_print(self)->None:"""Print a human-readable representation."""print(self.pretty_repr(html=is_interactive_env()))# noqa: T201
def__add__(self,other:Any)->ChatPromptTemplate:"""Combine two prompt templates. Args: other: Another prompt template. Returns: Combined prompt template. """fromlangchain_core.prompts.chatimportChatPromptTemplateprompt=ChatPromptTemplate(messages=[self])returnprompt+other