template: str the template string.
    Returns:
        a message prompt template of the appropriate type.
    """
    if message_type == "human":
        message: BaseMessagePromptTemplate = HumanMessagePromptTemplate.from_template(
            template
        )
    elif message_type == "ai":
        message = AIMessagePromptTemplate.from_template(template)
    elif message_type == "system":
        message = SystemMessagePromptTemplate.from_template(template)
    else:
        raise ValueError(
            f"Unexpected message type: {message_type}. Use one of 'human', 'ai', "
            f"or 'system'."
        )
    return message
def _convert_to_message(
    message: Union[
        BaseMessagePromptTemplate,
        BaseChatPromptTemplate,
        BaseMessage,
        Tuple[str, str],
        Tuple[Type, str],
        str,
    ]
) -> Union[BaseMessage, BaseMessagePromptTemplate, BaseChatPromptTemplate]:
    """Instantiate a message from a variety of message formats.
    The message format can be one of the following:
    - BaseMessagePromptTemplate
    - BaseMessage
    - 2-tuple of (role string, template); e.g., ("human", "{user_input}")
    - 2-tuple of (message class, template)
    - string: shorthand for ("human", template); e.g., "{user_input}"
    Args:
        message: a representation of a message in one of the supported formats
    Returns:
        an instance of a message or a message template
    """
    if isinstance(message, (BaseMessagePromptTemplate, BaseChatPromptTemplate)):
        _message: Union[
            BaseMessage, BaseMessagePromptTemplate, BaseChatPromptTemplate
        ] = message