💡 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 issue with calling cached_file for local directories, closes #825
davidmezzetti4b5164becaaa
diff --git a/src/python/txtai/models/pooling/factory.py b/src/python/txtai/models/pooling/factory.pyindex 131367d0..7e399f0d 100644--- a/src/python/txtai/models/pooling/factory.py+++ b/src/python/txtai/models/pooling/factory.py@@ -67,17 +67,12 @@ class PoolingFactory:# Default methodmethod = "meanpooling"- try:- # Load 1_Pooling/config.json file- config = PoolingFactory.load(path, "1_Pooling/config.json")-- # Set to CLS pooling if it's enabled and mean pooling is disabled- if config["pooling_mode_cls_token"] and not config["pooling_mode_mean_tokens"]:- method = "clspooling"+ # Load 1_Pooling/config.json file+ config = PoolingFactory.load(path, "1_Pooling/config.json")- # Ignore this error- except OSError:- pass+ # Set to CLS pooling if it's enabled and mean pooling is disabled+ if config and config["pooling_mode_cls_token"] and not config["pooling_mode_mean_tokens"]:+ method = "clspooling"return method@@ -97,13 +92,8 @@ class PoolingFactory:maxlength = None# Read max_seq_length from sentence_bert_config.json- try:- config = PoolingFactory.load(path, "sentence_bert_config.json")- maxlength = config.get("max_seq_length")-- # Ignore this error- except OSError:- pass+ config = PoolingFactory.load(path, "sentence_bert_config.json")+ maxlength = config.get("max_seq_length") if config else maxlengthreturn maxlength@@ -121,6 +111,15 @@ class PoolingFactory:"""# Download file and parse JSON- path = cached_file(path_or_repo_id=path, filename=name)- with open(path, encoding="utf-8") as f:- return json.load(f)+ config = None+ try:+ path = cached_file(path_or_repo_id=path, filename=name)+ if path:+ with open(path, encoding="utf-8") as f:+ config = json.load(f)++ # Ignore this error - invalid repo or directory+ except OSError:+ pass++ return configdiff --git a/src/python/txtai/pipeline/audio/texttospeech.py b/src/python/txtai/pipeline/audio/texttospeech.pyindex 0315180e..ed35cc54 100644--- a/src/python/txtai/pipeline/audio/texttospeech.py+++ b/src/python/txtai/pipeline/audio/texttospeech.py@@ -115,13 +115,14 @@ class TextToSpeech(Pipeline):True if name exists in path, False otherwise"""+ exists = Falsetry:# Check if file exists- cached_file(path_or_repo_id=path, filename=name)+ exists = cached_file(path_or_repo_id=path, filename=name) is not Noneexcept OSError:return False- return True+ return existsdef stream(self, texts, speaker):"""