mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-06 21:43:44 +00:00
Harrison/prompt template prefix (#888)
Co-authored-by: Gabriel Simmons <simmons.gabe@gmail.com>
This commit is contained in:
40
tests/unit_tests/prompts/test_few_shot_with_templates.py
Normal file
40
tests/unit_tests/prompts/test_few_shot_with_templates.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Test few shot prompt template."""
|
||||
|
||||
from langchain.prompts.few_shot_with_templates import FewShotPromptWithTemplates
|
||||
from langchain.prompts.prompt import PromptTemplate
|
||||
|
||||
EXAMPLE_PROMPT = PromptTemplate(
|
||||
input_variables=["question", "answer"], template="{question}: {answer}"
|
||||
)
|
||||
|
||||
|
||||
def test_prompttemplate_prefix_suffix() -> None:
|
||||
"""Test that few shot works when prefix and suffix are PromptTemplates."""
|
||||
prefix = PromptTemplate(
|
||||
input_variables=["content"], template="This is a test about {content}."
|
||||
)
|
||||
suffix = PromptTemplate(
|
||||
input_variables=["new_content"],
|
||||
template="Now you try to talk about {new_content}.",
|
||||
)
|
||||
|
||||
examples = [
|
||||
{"question": "foo", "answer": "bar"},
|
||||
{"question": "baz", "answer": "foo"},
|
||||
]
|
||||
prompt = FewShotPromptWithTemplates(
|
||||
suffix=suffix,
|
||||
prefix=prefix,
|
||||
input_variables=["content", "new_content"],
|
||||
examples=examples,
|
||||
example_prompt=EXAMPLE_PROMPT,
|
||||
example_separator="\n",
|
||||
)
|
||||
output = prompt.format(content="animals", new_content="party")
|
||||
expected_output = (
|
||||
"This is a test about animals.\n"
|
||||
"foo: bar\n"
|
||||
"baz: foo\n"
|
||||
"Now you try to talk about party."
|
||||
)
|
||||
assert output == expected_output
|
Reference in New Issue
Block a user