core[patch]: Update typing for template format to include jinja2 as a Literal (#24144)

Fixes #23929 via adjusting the typing
This commit is contained in:
Tibor Reiss 2024-07-16 15:09:42 +02:00 committed by GitHub
parent 6716379f0c
commit 1c753d1e81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1060,7 +1060,7 @@ class ChatPromptTemplate(BaseChatPromptTemplate):
def from_messages( def from_messages(
cls, cls,
messages: Sequence[MessageLikeRepresentation], messages: Sequence[MessageLikeRepresentation],
template_format: Literal["f-string", "mustache"] = "f-string", template_format: Literal["f-string", "mustache", "jinja2"] = "f-string",
) -> ChatPromptTemplate: ) -> ChatPromptTemplate:
"""Create a chat prompt template from a variety of message formats. """Create a chat prompt template from a variety of message formats.
@ -1274,7 +1274,7 @@ class ChatPromptTemplate(BaseChatPromptTemplate):
def _create_template_from_message_type( def _create_template_from_message_type(
message_type: str, message_type: str,
template: Union[str, list], template: Union[str, list],
template_format: Literal["f-string", "mustache"] = "f-string", template_format: Literal["f-string", "mustache", "jinja2"] = "f-string",
) -> BaseMessagePromptTemplate: ) -> BaseMessagePromptTemplate:
"""Create a message prompt template from a message type and template string. """Create a message prompt template from a message type and template string.
@ -1341,7 +1341,7 @@ def _create_template_from_message_type(
def _convert_to_message( def _convert_to_message(
message: MessageLikeRepresentation, message: MessageLikeRepresentation,
template_format: Literal["f-string", "mustache"] = "f-string", template_format: Literal["f-string", "mustache", "jinja2"] = "f-string",
) -> Union[BaseMessage, BaseMessagePromptTemplate, BaseChatPromptTemplate]: ) -> Union[BaseMessage, BaseMessagePromptTemplate, BaseChatPromptTemplate]:
"""Instantiate a message from a variety of message formats. """Instantiate a message from a variety of message formats.