From 888973bafe4f495c9e1c672cc9fbb36e0e3dfda9 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Wed, 10 Apr 2024 15:31:27 +0200 Subject: [PATCH] fix(prompt): allow "content" prompt var again --- langfuse/model.py | 3 ++- tests/test_prompt_compilation.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/langfuse/model.py b/langfuse/model.py index 42e8fe844..b6a81b32f 100644 --- a/langfuse/model.py +++ b/langfuse/model.py @@ -76,7 +76,8 @@ def _get_langchain_prompt_string(content: str): return re.sub(r"\{\{(.*?)\}\}", r"{\g<1>}", content) @staticmethod - def _compile_template_string(content: str, **kwargs) -> str: + def _compile_template_string(*args, **kwargs) -> str: + content = args[0] opening = "{{" closing = "}}" diff --git a/tests/test_prompt_compilation.py b/tests/test_prompt_compilation.py index d26b72835..c8b532157 100644 --- a/tests/test_prompt_compilation.py +++ b/tests/test_prompt_compilation.py @@ -169,3 +169,13 @@ def test_unescaped_JSON_variable_value(): ) def test_various_templates(template, kwargs, expected): assert BasePromptClient._compile_template_string(template, **kwargs) == expected + + +def test_content_var(): + template = "Hello, {{content}}!" + expected = "Hello, Thomas!" + + assert ( + BasePromptClient._compile_template_string(template, content="Thomas") + == expected + )