mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-08 04:25:46 +00:00
Apply lint
This commit is contained in:
parent
4b74e35532
commit
d42865a58f
@ -683,28 +683,48 @@ def test_prompt_with_template_variable_name_jinja2() -> None:
|
||||
assert prompt.invoke({"template": "bar"}).to_string() == "This is a bar test."
|
||||
|
||||
|
||||
def test_prompt_template_add_with_with_another_format():
|
||||
with pytest.raises(match=r"Cannot add templates"):
|
||||
def test_prompt_template_add_with_with_another_format() -> None:
|
||||
with pytest.raises(ValueError, match=r"Cannot add templates"):
|
||||
PromptTemplate.from_template("This is a {template}") + PromptTemplate.from_template("So {{this}} is", template_format="mustache")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"template_format, prompt1, prompt2",
|
||||
[
|
||||
("f-string", "This is a {variable}", ". This is {another_variable}"),
|
||||
pytest.param("jinja2", "This is a {{variable}}", ". This is {{another_variable}}", marks=[pytest.mark.requires("jinja2")]),
|
||||
("mustache", "This is a {{variable}}", ". This is {{another_variable}}"),
|
||||
]
|
||||
("template_format", "prompt1", "prompt2"),
|
||||
[
|
||||
("f-string", "This is a {variable}", ". This is {another_variable}"),
|
||||
pytest.param(
|
||||
"jinja2",
|
||||
"This is a {{variable}}",
|
||||
". This is {{another_variable}}",
|
||||
marks=[pytest.mark.requires("jinja2")]
|
||||
),
|
||||
("mustache", "This is a {{variable}}", ". This is {{another_variable}}"),
|
||||
]
|
||||
)
|
||||
def test_prompt_template_add(template_format: str, prompt1: str, prompt2: str) -> None:
|
||||
first_prompt = PromptTemplate.from_template(prompt1, template_format=template_format)
|
||||
second_prompt = PromptTemplate.from_template(prompt2, template_format=template_format)
|
||||
first_prompt = PromptTemplate.from_template(
|
||||
prompt1,
|
||||
template_format=template_format,
|
||||
)
|
||||
second_prompt = PromptTemplate.from_template(
|
||||
prompt2,
|
||||
template_format=template_format,
|
||||
)
|
||||
|
||||
concated_prompt = first_prompt + second_prompt
|
||||
prompt_of_concated = PromptTemplate.from_template(prompt1 + prompt2, template_format=template_format)
|
||||
prompt_of_concated = PromptTemplate.from_template(
|
||||
prompt1 + prompt2,
|
||||
template_format=template_format,
|
||||
)
|
||||
|
||||
assert concated_prompt.input_variables == prompt_of_concated.input_variables
|
||||
assert (
|
||||
concated_prompt.format(variable="template", another_variable="other_template") ==
|
||||
prompt_of_concated.format(variable="template", another_variable="other_template")
|
||||
)
|
||||
concated_prompt.format(
|
||||
variable="template",
|
||||
another_variable="other_template",
|
||||
) ==
|
||||
prompt_of_concated.format(
|
||||
variable="template",
|
||||
another_variable="other_template",
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user