@ -13,6 +13,27 @@ def test_prompt_valid() -> None:
assert prompt . input_variables == input_variables
def test_prompt_from_template ( ) - > None :
""" Test prompts can be constructed from a template. """
# Single input variable.
template = " This is a {foo} test. "
prompt = PromptTemplate . from_template ( template )
expected_prompt = PromptTemplate ( template = template , input_variables = [ " foo " ] )
assert prompt == expected_prompt
# Multiple input variables.
template = " This {bar} is a {foo} test. "
prompt = PromptTemplate . from_template ( template )
expected_prompt = PromptTemplate ( template = template , input_variables = [ " bar " , " foo " ] )
assert prompt == expected_prompt
# Multiple input variables with repeats.
template = " This {bar} is a {foo} test {foo} . "
prompt = PromptTemplate . from_template ( template )
expected_prompt = PromptTemplate ( template = template , input_variables = [ " bar " , " foo " ] )
assert prompt == expected_prompt
def test_prompt_missing_input_variables ( ) - > None :
""" Test error is raised when input variables are not provided. """
template = " This is a {foo} test. "