💡 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 bug with xmltodict not being wrapped in a conditional import, closes #146
davidmezzettid9b4afaa7e97
diff --git a/src/python/txtai/workflow/task/service.py b/src/python/txtai/workflow/task/service.pyindex 70077472..c2a5ae96 100644--- a/src/python/txtai/workflow/task/service.py+++ b/src/python/txtai/workflow/task/service.py@@ -2,8 +2,14 @@ServiceTask module"""-import requests-import xmltodict+# Conditional import+try:+ import requests+ import xmltodict++ XML_TO_DICT = True+except ImportError:+ XML_TO_DICT = Falsefrom .base import Task@@ -14,6 +20,9 @@ class ServiceTask(Task):"""def __init__(self, action=None, select=None, unpack=True, url=None, method=None, params=None, batch=True, extract=None):+ if not XML_TO_DICT:+ raise ImportError('ServiceTask is not available - install "workflow" extra to enable')+super().__init__(action, select, unpack)# Save URL, method and parameter defaultsdiff --git a/test/python/testoptional.py b/test/python/testoptional.pyindex ecf6d0cd..5c553b64 100644--- a/test/python/testoptional.py+++ b/test/python/testoptional.py@@ -10,8 +10,7 @@ from txtai.ann import ANNFactoryfrom txtai.models import OnnxModelfrom txtai.pipeline import HFOnnx, MLOnnx, Segmentation, Tabular, Textractor, Transcription, Translationfrom txtai.vectors import VectorsFactory-from txtai.workflow.task.image import ImageTask-from txtai.workflow.task.storage import StorageTask+from txtai.workflow import ImageTask, ServiceTask, StorageTaskclass TestOptional(unittest.TestCase):@@ -42,6 +41,7 @@ class TestOptional(unittest.TestCase):txtai.vectors.transformers.SENTENCE_TRANSFORMERS = not txtai.vectors.transformers.SENTENCE_TRANSFORMERStxtai.workflow.task.image.PIL = not txtai.workflow.task.image.PIL+ txtai.workflow.task.service.XML_TO_DICT = not txtai.workflow.task.service.XML_TO_DICTtxtai.workflow.task.storage.LIBCLOUD = not txtai.workflow.task.storage.LIBCLOUD@classmethod@@ -126,5 +126,8 @@ class TestOptional(unittest.TestCase):with self.assertRaises(ImportError):ImageTask()+ with self.assertRaises(ImportError):+ ServiceTask()+with self.assertRaises(ImportError):StorageTask()