Source code for langchain.prompts.chat
"""Chat prompt template."""
from __future__ import annotations
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Any, Callable, List, Sequence, Tuple, Type, TypeVar, Union
from pydantic import Field, root_validator
from langchain.load.serializable import Serializable
from langchain.prompts.base import StringPromptTemplate
from langchain.prompts.prompt import PromptTemplate
from langchain.schema import (
    BasePromptTemplate,
    PromptValue,
)
from langchain.schema.messages import (
    AIMessage,
    BaseMessage,
    ChatMessage,
    HumanMessage,
    SystemMessage,
    get_buffer_string,
)
[docs]class BaseMessagePromptTemplate(Serializable, ABC):
    """Base class for message prompt templates."""
    @property
    def lc_serializable(self) -> bool:
        """Whether this object should be serialized.
        Returns:
            Whether this object should be serialized.
        """
        return True
[docs]    @abstractmethod
    def format_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.
        """
    @property
    @abstractmethod
    def input_variables(self) -> List[str]:
        """Input variables for this prompt template.
        Returns:
            List of input variables.
        """
    def __add__(self, other: Any) -> ChatPromptTemplate:
        """Combine two prompt templates.
        Args:
            other: Another prompt template.
        Returns:
            Combined prompt template.
        """
        prompt = ChatPromptTemplate(messages=[self])