Include "no escape" and "inverted section" mustache vars in Prompt.input_variables and Prompt.input_schema (#22981)

This commit is contained in:
Nuno Campos
2024-06-17 19:24:13 -07:00
committed by GitHub
parent 7a0b36501f
commit f01f12ce1e
2 changed files with 31 additions and 11 deletions

View File

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