💡 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
Write a URL with no path to a file when RetrieveTask keeps the directory structure (#1487)
sarankumare5d8d43042ed
diff --git a/src/python/txtai/workflow/task/retrieve.py b/src/python/txtai/workflow/task/retrieve.pyindex 37fc1513..cfd0a62c 100644--- a/src/python/txtai/workflow/task/retrieve.py+++ b/src/python/txtai/workflow/task/retrieve.py@@ -56,8 +56,8 @@ class RetrieveTask(Task):path = os.path.join(self.directory, os.path.basename(path) or urlparse(element).hostname or "download")directory = Noneelse:- # Derive output path- path = os.path.join(self.directory, os.path.normpath(path.lstrip("/")))+ # Derive output path, a URL with no path falls back to its hostname, then to "download"+ path = os.path.join(self.directory, os.path.normpath(path.lstrip("/") or urlparse(element).hostname or "download"))directory = os.path.dirname(path)# Validate output pathdiff --git a/test/python/testworkflow.py b/test/python/testworkflow.pyindex 7f1e0cd9..839bb74e 100644--- a/test/python/testworkflow.py+++ b/test/python/testworkflow.py@@ -525,6 +525,11 @@ class TestWorkflow(unittest.TestCase):self.assertTrue(first.endswith("a.example.com"))self.assertTrue(second.endswith("b.example.com"))+ # Same for a URL with no path when the directory structure is kept+ path = RetrieveTask(directory=directory, flatten=False).prepare("https://c.example.com/")+ self.assertTrue(os.path.isfile(path))+ self.assertTrue(path.endswith("c.example.com"))+def testRetrieveLocalFilenames(self):"""Test that local filenames are preserved instead of parsed as URLs