💡 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
Improve temporary file creation logic
davidmezzettid758e1fa761e
diff --git a/src/python/txtai/cloud/hub.py b/src/python/txtai/cloud/hub.pyindex ea817f88..ba0dea06 100644--- a/src/python/txtai/cloud/hub.py+++ b/src/python/txtai/cloud/hub.py@@ -88,10 +88,14 @@ class HuggingFaceHub(Cloud):content += "embeddings filter=lfs diff=lfs merge=lfs -text\n"# pylint: disable=R1732- tmp = tempfile.NamedTemporaryFile()- with open(tmp.name, "w", encoding="utf-8") as f:- f.write(content)+ with tempfile.NamedTemporaryFile(mode="w", delete=False) as tmp:+ tmp.write(content)+ attributes = tmp.name+ # Upload filehuggingface_hub.upload_file(- repo_id=self.config["container"], token=self.config.get("token"), path_or_fileobj=tmp.name, path_in_repo=os.path.basename(path)+ repo_id=self.config["container"], token=self.config.get("token"), path_or_fileobj=attributes, path_in_repo=os.path.basename(path))++ # Remove temporary file+ os.remove(attributes)diff --git a/test/python/testcloud.py b/test/python/testcloud.pyindex 2c182ebc..e748c2c2 100644--- a/test/python/testcloud.py+++ b/test/python/testcloud.py@@ -125,10 +125,9 @@ class TestCloud(unittest.TestCase):# Initialize attributes file# pylint: disable=R1732- tmp = tempfile.NamedTemporaryFile()- with open(tmp.name, "w", encoding="utf-8") as f:- f.write("*.bin filter=lfs diff=lfs merge=lfs -text\n")- attributes = tmp.name+ with tempfile.NamedTemporaryFile(mode="w", delete=False) as tmp:+ tmp.write("*.bin filter=lfs diff=lfs merge=lfs -text\n")+ attributes = tmp.name# Run tests with uncompressed and compressed indexfor path in [f"cloud.{provider}", f"cloud.{provider}.tar.gz"]: