From 5af2c51e78f30408e8acfeece00242ff18b31cb6 Mon Sep 17 00:00:00 2001 From: Shuqian Date: Sun, 4 Jun 2023 07:55:58 +0800 Subject: [PATCH] refactor: BaseStringMessagePromptTemplate from_template method (#5332) # refactor BaseStringMessagePromptTemplate from_template method Refactor the `from_template` method of the `BaseStringMessagePromptTemplate` class to allow passing keyword arguments to the `from_template` method of `PromptTemplate`. Enable the usage of arguments like `template_format`. In my scenario, I intend to utilize Jinja2 for formatting the human message prompt in the chat template. ## Who can review? Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested: --------- Co-authored-by: Dev 2049 --- langchain/prompts/chat.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/langchain/prompts/chat.py b/langchain/prompts/chat.py index 9df7cece..89fb10b0 100644 --- a/langchain/prompts/chat.py +++ b/langchain/prompts/chat.py @@ -69,9 +69,12 @@ class BaseStringMessagePromptTemplate(BaseMessagePromptTemplate, ABC): @classmethod def from_template( - cls: Type[MessagePromptTemplateT], template: str, **kwargs: Any + cls: Type[MessagePromptTemplateT], + template: str, + template_format: str = "f-string", + **kwargs: Any, ) -> MessagePromptTemplateT: - prompt = PromptTemplate.from_template(template) + prompt = PromptTemplate.from_template(template, template_format=template_format) return cls(prompt=prompt, **kwargs) @classmethod