Skip to content

armgit / txtai

Public Imported from GitHub
0

💡 All-in-one AI framework for semantic search, LLM orchestration and language model workflows

Update cached_file exception handling, closes #889

davidmezzettie97237ab299b
diff --git a/src/python/txtai/models/pooling/factory.py b/src/python/txtai/models/pooling/factory.py
index 7e399f0d..d61dabb4 100644
--- a/src/python/txtai/models/pooling/factory.py
+++ b/src/python/txtai/models/pooling/factory.py
@@ -5,6 +5,7 @@ Factory module
import json
import os
+from huggingface_hub.errors import HFValidationError
from transformers.utils import cached_file
from .base import Pooling
@@ -119,7 +120,7 @@ class PoolingFactory:
config = json.load(f)
# Ignore this error - invalid repo or directory
- except OSError:
+ except (HFValidationError, OSError):
pass
return config
diff --git a/src/python/txtai/pipeline/audio/texttospeech.py b/src/python/txtai/pipeline/audio/texttospeech.py
index df1320f0..af23a388 100644
--- a/src/python/txtai/pipeline/audio/texttospeech.py
+++ b/src/python/txtai/pipeline/audio/texttospeech.py
@@ -25,6 +25,7 @@ import yaml
import numpy as np
+from huggingface_hub.errors import HFValidationError
from transformers import SpeechT5Processor
from transformers.utils import cached_file
@@ -131,7 +132,7 @@ class TextToSpeech(Pipeline):
try:
# Check if file exists
exists = cached_file(path_or_repo_id=path, filename=name) is not None
- except OSError:
+ except (HFValidationError, OSError):
return False
return exists
diff --git a/src/python/txtai/pipeline/text/entity.py b/src/python/txtai/pipeline/text/entity.py
index 61dde68b..12ec712e 100644
--- a/src/python/txtai/pipeline/text/entity.py
+++ b/src/python/txtai/pipeline/text/entity.py
@@ -10,6 +10,7 @@ try:
except ImportError:
GLINER = False
+from huggingface_hub.errors import HFValidationError
from transformers.utils import cached_file
from ...models import Models
@@ -88,7 +89,7 @@ class Entity(HFPipeline):
return cached_file(path_or_repo_id=path, filename="gliner_config.json") is not None
# Ignore this error - invalid repo or directory
- except OSError:
+ except (HFValidationError, OSError):
pass
return False
diff --git a/src/python/txtai/vectors/m2v.py b/src/python/txtai/vectors/m2v.py
index f46903d0..46c2f18d 100644
--- a/src/python/txtai/vectors/m2v.py
+++ b/src/python/txtai/vectors/m2v.py
@@ -4,6 +4,7 @@ Model2Vec module
import json
+from huggingface_hub.errors import HFValidationError
from transformers.utils import cached_file
# Conditional import
@@ -43,7 +44,7 @@ class Model2Vec(Vectors):
return config.get("model_type") == "model2vec"
# Ignore this error - invalid repo or directory
- except OSError:
+ except (HFValidationError, OSError):
pass
return False
diff --git a/src/python/txtai/vectors/words.py b/src/python/txtai/vectors/words.py
index 457cc763..81e6700a 100644
--- a/src/python/txtai/vectors/words.py
+++ b/src/python/txtai/vectors/words.py
@@ -11,6 +11,7 @@ from multiprocessing import Pool
import numpy as np
+from huggingface_hub.errors import HFValidationError
from transformers.utils import cached_file
# Conditional import
@@ -98,7 +99,7 @@ class WordVectors(Vectors):
return config.get("model_type") == "staticvectors"
# Ignore this error - invalid repo or directory
- except OSError:
+ except (HFValidationError, OSError):
pass
return False