mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 19:47:13 +00:00
Include "no escape" and "inverted section" mustache vars in Prompt.input_variables and Prompt.input_schema (#22981)
This commit is contained in:
@@ -67,7 +67,7 @@ def test_mustache_prompt_from_template() -> None:
|
||||
}
|
||||
|
||||
# Multiple input variables with repeats.
|
||||
template = "This {{bar}} is a {{foo}} test {{foo}}."
|
||||
template = "This {{bar}} is a {{foo}} test {{&foo}}."
|
||||
prompt = PromptTemplate.from_template(template, template_format="mustache")
|
||||
assert prompt.format(bar="baz", foo="bar") == "This baz is a bar test bar."
|
||||
assert prompt.input_variables == ["bar", "foo"]
|
||||
@@ -81,7 +81,7 @@ def test_mustache_prompt_from_template() -> None:
|
||||
}
|
||||
|
||||
# Nested variables.
|
||||
template = "This {{obj.bar}} is a {{obj.foo}} test {{foo}}."
|
||||
template = "This {{obj.bar}} is a {{obj.foo}} test {{{foo}}}."
|
||||
prompt = PromptTemplate.from_template(template, template_format="mustache")
|
||||
assert prompt.format(obj={"bar": "foo", "foo": "bar"}, foo="baz") == (
|
||||
"This foo is a bar test baz."
|
||||
@@ -167,6 +167,22 @@ def test_mustache_prompt_from_template() -> None:
|
||||
},
|
||||
}
|
||||
|
||||
template = """This{{^foo}}
|
||||
no foos
|
||||
{{/foo}}is a test."""
|
||||
prompt = PromptTemplate.from_template(template, template_format="mustache")
|
||||
assert prompt.format() == (
|
||||
"""This
|
||||
no foos
|
||||
is a test."""
|
||||
)
|
||||
assert prompt.input_variables == ["foo"]
|
||||
assert prompt.input_schema.schema() == {
|
||||
"title": "PromptInput",
|
||||
"type": "object",
|
||||
"properties": {"foo": {"title": "Foo", "type": "object"}},
|
||||
}
|
||||
|
||||
|
||||
def test_prompt_from_template_with_partial_variables() -> None:
|
||||
"""Test prompts can be constructed from a template with partial variables."""
|
||||
|
Reference in New Issue
Block a user