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:

<!-- For a quicker response, figure out the right person to tag with @

  @hwchase17 - project lead

  Models
  - @hwchase17
  - @agola11
  - @jonasalexander 

 -->

---------

Co-authored-by: Dev 2049 <dev.dev2049@gmail.com>
searx_updates
Shuqian 12 months ago committed by GitHub
parent d3bdb8ea6d
commit 5af2c51e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save