💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows
Python agentsaiai-agentsembeddingsinformation-retrievallanguage-modellarge-language-modelsllmnlppythonragretrieval-augmented-generationsearchsearch-enginesemantic-searchsentence-embeddingstransformerstxtaivector-databasevector-search
Preserve falsy TemplateTask rule matches (#1261)
HuaTNA48a34e21c3f5
diff --git a/src/python/txtai/workflow/task/template.py b/src/python/txtai/workflow/task/template.pyindex 2fae880d..c8522a5f 100644--- a/src/python/txtai/workflow/task/template.py+++ b/src/python/txtai/workflow/task/template.py@@ -37,7 +37,7 @@ class TemplateTask(Task):def prepare(self, element):# Check if element matches any processing rulesmatch = self.match(element)- if match:+ if match is not None:return match# Apply template processing, if applicablediff --git a/test/python/testworkflow.py b/test/python/testworkflow.pyindex 9c1d2754..a335e24c 100644--- a/test/python/testworkflow.py+++ b/test/python/testworkflow.py@@ -485,6 +485,26 @@ class TestWorkflow(unittest.TestCase):results = list(workflow([{"text": "prompt"}]))self.assertEqual(results[0], "This is a prompt")+ def testTemplateRulesFalsy(self):+ """+ Test that falsy rule matches bypass template formatting+ """++ for value in ("", 0, False):+ with self.subTest(value=value):+ workflow = Workflow([TemplateTask(template="This is a {text}", rules={"text": value})])+ results = list(workflow([{"text": value}, {"text": "prompt"}]))+ self.assertEqual(results, [value, "This is a prompt"])+ self.assertIs(type(results[0]), type(value))++ def testTemplateRulesMissingField(self):+ """+ Test that a falsy rule match does not require template fields+ """++ workflow = Workflow([TemplateTask(template="This is a {text}", rules={"status": ""})])+ self.assertEqual(list(workflow([{"status": ""}])), [""])+def testTemplateRag(self):"""Test rag template task