💡 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
Fix TemplateTask.match KeyError when a rule key is missing from element (#1141)
Andrew Chen79a28641b24e
diff --git a/src/python/txtai/workflow/task/template.py b/src/python/txtai/workflow/task/template.pyindex 7b3e9bad..2fae880d 100644--- a/src/python/txtai/workflow/task/template.py+++ b/src/python/txtai/workflow/task/template.py@@ -90,7 +90,7 @@ class TemplateTask(Task):if self.rules and isinstance(element, dict):# Check if any rules are matchedfor key, value in self.rules.items():- if element[key] == value:+ if key in element and element[key] == value:return element[key]return Nonediff --git a/test/python/testworkflow.py b/test/python/testworkflow.pyindex 6acbefcc..5851d73f 100644--- a/test/python/testworkflow.py+++ b/test/python/testworkflow.py@@ -454,6 +454,11 @@ class TestWorkflow(unittest.TestCase):results = list(workflow([{"text": "prompt"}]))self.assertEqual(results[0], "This is a prompt")+ # Test rule key missing from element+ workflow = Workflow([TemplateTask(template="This is a {text}", rules={"category": "skip"})])+ results = list(workflow([{"text": "prompt"}]))+ self.assertEqual(results[0], "This is a prompt")+def testTemplateRag(self):"""Test rag template task