💡 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
Modify method signature and add additional test
davidmezzetti34f625313c47
diff --git a/src/python/txtai/pipeline/labels.py b/src/python/txtai/pipeline/labels.pyindex 866fff0a..fa83c9e4 100644--- a/src/python/txtai/pipeline/labels.py+++ b/src/python/txtai/pipeline/labels.py@@ -104,16 +104,17 @@ class Labels(HFPipeline):return list(self.pipeline.model.config.id2label.values())- def tokenize(self, **kwargs):+ def tokenize(self, *args, **kwargs):"""Tokenization method that forces truncation=True.Args:- kwargs: arguments+ args: arguments+ kwargs: named argumentsReturns:tokenized output"""kwargs["truncation"] = True- return self.tokenizer(**kwargs)+ return self.tokenizer(*args, **kwargs)diff --git a/test/python/testonnx.py b/test/python/testonnx.pyindex e53102aa..0c6ed9aa 100644--- a/test/python/testonnx.py+++ b/test/python/testonnx.py@@ -6,7 +6,10 @@ import osimport tempfileimport unittest+from collections import OrderedDict+from txtai.embeddings import Embeddings+from txtai.models import OnnxModelfrom txtai.pipeline import HFOnnx, HFTrainer, Labels, Questions@@ -23,6 +26,44 @@ class TestOnnx(unittest.TestCase):cls.data = [{"text": "Dogs", "label": 0}, {"text": "dog", "label": 0}, {"text": "Cats", "label": 1}, {"text": "cat", "label": 1}] * 100+ def testAutoAdd(self):+ """+ Tests methods for adding ONNX models to auto classes+ """++ class Mapping(OrderedDict):+ """+ Helper class to support autoadd tests.+ """++ def __init__(self):+ super().__init__()++ self._config_mapping = {}+ self._reverse_config_mapping = {}+ self._model_mapping = {}+ self._modules = {}++ # Export model to ONNX, use default parameters+ onnx = HFOnnx()+ model = OnnxModel(onnx("google/bert_uncased_L-2_H-128_A-2"))++ # Test lazy auto mapping+ mapping = Mapping()+ model.autoadd(mapping, "key", "value")++ # pylint: disable=W0212+ self.assertTrue("key" in mapping._config_mapping)+ self.assertTrue("value" in mapping._reverse_config_mapping)+ self.assertTrue("key" in mapping._model_mapping)+ self.assertTrue("key" in mapping._modules)++ # Test mapping backed by dict+ mapping = {}+ model.autoadd(mapping, "key", "value")++ self.assertTrue("key" in mapping)+def testDefault(self):"""Test exporting an ONNX model with default parameters