From 143049c90f99d919c72c341142fc2aa85f813965 Mon Sep 17 00:00:00 2001 From: Josep Pon Farreny Date: Wed, 22 Nov 2023 02:48:38 +0100 Subject: [PATCH] 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 Co-authored-by: Bagatur --- libs/core/langchain_core/prompts/chat.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libs/core/langchain_core/prompts/chat.py b/libs/core/langchain_core/prompts/chat.py index 9c3fae871c4..fc10ef179c2 100644 --- a/libs/core/langchain_core/prompts/chat.py +++ b/libs/core/langchain_core/prompts/chat.py @@ -8,6 +8,7 @@ from typing import ( Callable, Dict, List, + Optional, Sequence, Set, Tuple, @@ -136,6 +137,7 @@ class BaseStringMessagePromptTemplate(BaseMessagePromptTemplate, ABC): cls: Type[MessagePromptTemplateT], template: str, template_format: str = "f-string", + partial_variables: Optional[Dict[str, Any]] = None, **kwargs: Any, ) -> MessagePromptTemplateT: """Create a class from a string template. @@ -143,12 +145,21 @@ class BaseStringMessagePromptTemplate(BaseMessagePromptTemplate, ABC): Args: template: a 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. Returns: 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) @classmethod