💡 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
Update constructor signatures for consistency across pipelines, update documentation
davidmezzetti5b572dd553fe
diff --git a/src/python/txtai/pipeline/audio/texttospeech.py b/src/python/txtai/pipeline/audio/texttospeech.pyindex 4eca3a35..cd322f3e 100644--- a/src/python/txtai/pipeline/audio/texttospeech.py+++ b/src/python/txtai/pipeline/audio/texttospeech.py@@ -27,7 +27,7 @@ class TextToSpeech(Pipeline):Generates speech from text"""- def __init__(self, path="neuml/ljspeech-jets-onnx", maxtokens=512):+ def __init__(self, path=None, maxtokens=512):"""Creates a new TextToSpeech pipeline.@@ -39,6 +39,9 @@ class TextToSpeech(Pipeline):if not TTS:raise ImportError('TextToSpeech pipeline is not available - install "pipeline" extra to enable')+ # Default path+ path = path if path else "neuml/ljspeech-jets-onnx"+# Get path to model and configconfig = hf_hub_download(path, filename="config.yaml")model = hf_hub_download(path, filename="model.onnx")diff --git a/src/python/txtai/pipeline/text/translation.py b/src/python/txtai/pipeline/text/translation.pyindex 88af7213..baa0177f 100644--- a/src/python/txtai/pipeline/text/translation.py+++ b/src/python/txtai/pipeline/text/translation.py@@ -26,7 +26,7 @@ class Translation(HFModel):# Default language detection modelDEFAULT_LANG_DETECT = "https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz"- def __init__(self, path="facebook/m2m100_418M", quantize=False, gpu=True, batch=64, langdetect=None, findmodels=True):+ def __init__(self, path=None, quantize=False, gpu=True, batch=64, langdetect=None, findmodels=True):"""Constructs a new language translation pipeline.@@ -36,12 +36,13 @@ class Translation(HFModel):quantize: if model should be quantized, defaults to Falsegpu: True/False if GPU should be enabled, also supports a GPU device idbatch: batch size used to incrementally process content- langdetect: path to language detection model, uses a default path if not provided+ langdetect: set a custom language detection function, method must take a list of strings and return+ language codes for each, uses default language detector if not providedfindmodels: True/False if the Hugging Face Hub will be searched for source-target translation models"""# Call parent constructor- super().__init__(path, quantize, gpu, batch)+ super().__init__(path if path else "facebook/m2m100_418M", quantize, gpu, batch)# Language detectionself.detector = None@@ -125,7 +126,7 @@ class Translation(HFModel):list of languages"""- # Backwards compatible to load fasttext model+ # Default detectorif not self.langdetect or isinstance(self.langdetect, str):return self.defaultdetect(texts)@@ -134,8 +135,7 @@ class Translation(HFModel):def defaultdetect(self, texts):"""- Detects the language for each element in texts.- Default path that uses fasttext.+ Default fasttext language detection model.Args:texts: list of text@@ -144,17 +144,16 @@ class Translation(HFModel):list of languages"""- path = self.langdetect- if not path:- path = Translation.DEFAULT_LANG_DETECT-- if not FASTTEXT:- raise ImportError('Language detection is not available - install "pipeline" extra to enable')-if not self.detector:+ if not FASTTEXT:+ raise ImportError('Language detection is not available - install "pipeline" extra to enable')+# Suppress unnecessary warningfasttext.FastText.eprint = lambda x: None+ # Get model path+ path = self.langdetect if self.langdetect else Translation.DEFAULT_LANG_DETECT+# Load language detection modelpath = cached_download(path, legacy_cache_layout=True)self.detector = fasttext.load_model(path)