forked from Archives/langchain
W.r.t recent changes, ChatPromptTemplate does not accepting partial variables. This PR should fix that issue. Fixes #6431 #### Who can review? @hwchase17 --------- Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
parent
02c0a1e77e
commit
6efd5fa2b9
@ -168,6 +168,8 @@ class ChatPromptTemplate(BaseChatPromptTemplate, ABC):
|
||||
for message in messages:
|
||||
if isinstance(message, BaseMessagePromptTemplate):
|
||||
input_vars.update(message.input_variables)
|
||||
if "partial_variables" in values:
|
||||
input_vars = input_vars - set(values["partial_variables"])
|
||||
if "input_variables" in values:
|
||||
if input_vars != set(values["input_variables"]):
|
||||
raise ValueError(
|
||||
|
@ -162,3 +162,31 @@ def test_infer_variables() -> None:
|
||||
messages = [HumanMessagePromptTemplate.from_template("{foo}")]
|
||||
prompt = ChatPromptTemplate(messages=messages)
|
||||
assert prompt.input_variables == ["foo"]
|
||||
|
||||
|
||||
def test_chat_valid_with_partial_variables() -> None:
|
||||
messages = [
|
||||
HumanMessagePromptTemplate.from_template(
|
||||
"Do something with {question} using {context} giving it like {formatins}"
|
||||
)
|
||||
]
|
||||
prompt = ChatPromptTemplate(
|
||||
messages=messages,
|
||||
input_variables=["question", "context"],
|
||||
partial_variables={"formatins": "some structure"},
|
||||
)
|
||||
assert set(prompt.input_variables) == set(["question", "context"])
|
||||
assert prompt.partial_variables == {"formatins": "some structure"}
|
||||
|
||||
|
||||
def test_chat_valid_infer_variables() -> None:
|
||||
messages = [
|
||||
HumanMessagePromptTemplate.from_template(
|
||||
"Do something with {question} using {context} giving it like {formatins}"
|
||||
)
|
||||
]
|
||||
prompt = ChatPromptTemplate(
|
||||
messages=messages, partial_variables={"formatins": "some structure"}
|
||||
)
|
||||
assert set(prompt.input_variables) == set(["question", "context"])
|
||||
assert prompt.partial_variables == {"formatins": "some structure"}
|
||||
|
Loading…
Reference in New Issue
Block a user