-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathio.py
More file actions
31 lines (23 loc) · 891 Bytes
/
io.py
File metadata and controls
31 lines (23 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Launch Input/Output utils."""
import os
from typing import Any
import smart_open
from model_engine_server.core.config import infra_config
def open_wrapper(uri: str, mode: str = "rt", **kwargs):
client: Any
try:
cloud_provider = infra_config().cloud_provider
except Exception:
cloud_provider = "aws"
if cloud_provider == "azure":
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
client = BlobServiceClient(
f"https://{os.getenv('ABS_ACCOUNT_NAME')}.blob.core.windows.net",
DefaultAzureCredential(),
)
else:
from model_engine_server.infra.gateways.s3_utils import get_s3_client
client = get_s3_client(kwargs)
transport_params = {"client": client}
return smart_open.open(uri, mode, transport_params=transport_params)