-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1165 from Shivam-19agg/add-azure-storage
Added the Azure-storage option for document sources.
- Loading branch information
Showing
7 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from azure.storage.blob import BlobServiceClient | ||
import os | ||
import tempfile | ||
|
||
class AzureDocumentLoader: | ||
def __init__(self, container_name, connection_string): | ||
self.client = BlobServiceClient.from_connection_string(connection_string) | ||
self.container = self.client.get_container_client(container_name) | ||
|
||
async def load(self): | ||
"""Download all blobs to temp files and return their paths.""" | ||
temp_dir = tempfile.mkdtemp() | ||
blobs = self.container.list_blobs() | ||
file_paths = [] | ||
for blob in blobs: | ||
blob_client = self.container.get_blob_client(blob.name) | ||
local_path = os.path.join(temp_dir, blob.name) | ||
with open(local_path, "wb") as f: | ||
blob_data = blob_client.download_blob() | ||
f.write(blob_data.readall()) | ||
file_paths.append(local_path) | ||
return file_paths # Pass to existing DocumentLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ unstructured | |
json_repair | ||
json5 | ||
loguru | ||
|
||
azure-storage-blob | ||
# uncomment for testing | ||
# pytest | ||
# pytest-asyncio |