mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-01 02:50:47 +00:00
Added partial_variables to BaseStringMessagePromptTemplate.from_template(...) (#13645)
**Description:** BaseStringMessagePromptTemplate.from_template was passing the value of partial_variables into cls(...) via **kwargs, rather than passing it to PromptTemplate.from_template. Which resulted in those *partial_variables being* lost and becoming required *input_variables*. Co-authored-by: Josep Pon Farreny <josep.pon-farreny@siemens.com> Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
c5ae9f832d
commit
143049c90f
@@ -8,6 +8,7 @@ from typing import (
|
|||||||
Callable,
|
Callable,
|
||||||
Dict,
|
Dict,
|
||||||
List,
|
List,
|
||||||
|
Optional,
|
||||||
Sequence,
|
Sequence,
|
||||||
Set,
|
Set,
|
||||||
Tuple,
|
Tuple,
|
||||||
@@ -136,6 +137,7 @@ class BaseStringMessagePromptTemplate(BaseMessagePromptTemplate, ABC):
|
|||||||
cls: Type[MessagePromptTemplateT],
|
cls: Type[MessagePromptTemplateT],
|
||||||
template: str,
|
template: str,
|
||||||
template_format: str = "f-string",
|
template_format: str = "f-string",
|
||||||
|
partial_variables: Optional[Dict[str, Any]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> MessagePromptTemplateT:
|
) -> MessagePromptTemplateT:
|
||||||
"""Create a class from a string template.
|
"""Create a class from a string template.
|
||||||
@@ -143,12 +145,21 @@ class BaseStringMessagePromptTemplate(BaseMessagePromptTemplate, ABC):
|
|||||||
Args:
|
Args:
|
||||||
template: a template.
|
template: a template.
|
||||||
template_format: format of the template.
|
template_format: format of the template.
|
||||||
|
partial_variables: A dictionary of variables that can be used to partially
|
||||||
|
fill in the template. For example, if the template is
|
||||||
|
`"{variable1} {variable2}"`, and `partial_variables` is
|
||||||
|
`{"variable1": "foo"}`, then the final prompt will be
|
||||||
|
`"foo {variable2}"`.
|
||||||
**kwargs: keyword arguments to pass to the constructor.
|
**kwargs: keyword arguments to pass to the constructor.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A new instance of this class.
|
A new instance of this class.
|
||||||
"""
|
"""
|
||||||
prompt = PromptTemplate.from_template(template, template_format=template_format)
|
prompt = PromptTemplate.from_template(
|
||||||
|
template,
|
||||||
|
template_format=template_format,
|
||||||
|
partial_variables=partial_variables,
|
||||||
|
)
|
||||||
return cls(prompt=prompt, **kwargs)
|
return cls(prompt=prompt, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Reference in New Issue
Block a user