diff --git a/haystack/nodes/prompt/prompt_node.py b/haystack/nodes/prompt/prompt_node.py index 4f17881f1..acc652884 100644 --- a/haystack/nodes/prompt/prompt_node.py +++ b/haystack/nodes/prompt/prompt_node.py @@ -173,6 +173,9 @@ class PromptTemplate(BasePromptTemplate, ABC): prompt_prepared: str = template.substitute(template_input) yield prompt_prepared + def __repr__(self): + return f"PromptTemplate(name={self.name}, prompt_text={self.prompt_text}, prompt_params={self.prompt_params})" + class PromptModelInvocationLayer: """ diff --git a/test/nodes/test_prompt_node.py b/test/nodes/test_prompt_node.py index de15ecac7..41fda073d 100644 --- a/test/nodes/test_prompt_node.py +++ b/test/nodes/test_prompt_node.py @@ -51,6 +51,13 @@ def test_prompt_templates(): assert p.prompt_text == "Here is some fake template with variable $baz" +def test_prompt_template_repr(): + p = PromptTemplate("t", "Here is variable $baz") + desired_repr = "PromptTemplate(name=t, prompt_text=Here is variable $baz, prompt_params=['baz'])" + assert repr(p) == desired_repr + assert str(p) == desired_repr + + def test_create_prompt_model(): model = PromptModel("google/flan-t5-small") assert model.model_name_or_path == "google/flan-t5-small"