跳至主要內容

Huawei OBS 目錄

以下程式碼示範如何從華為 OBS(物件儲存服務)載入物件作為文件。

# Install the required package
# pip install esdk-obs-python
from langchain_community.document_loaders import OBSDirectoryLoader
API 參考:OBSDirectoryLoader
endpoint = "your-endpoint"
# Configure your access credentials\n
config = {"ak": "your-access-key", "sk": "your-secret-key"}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

指定載入的前綴

如果您想從儲存桶載入具有特定前綴的物件,可以使用以下程式碼

loader = OBSDirectoryLoader(
"your-bucket-name", endpoint=endpoint, config=config, prefix="test_prefix"
)
loader.load()

從 ECS 取得驗證資訊

如果您的 langchain 部署在華為雲 ECS 上,並且已設定了代理,則載入器可以直接從 ECS 取得安全權杖,而無需存取金鑰和秘密金鑰。

config = {"get_token_from_ecs": True}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

使用公共儲存桶

如果您的儲存桶的儲存桶策略允許匿名存取(匿名使用者具有listBucketGetObject 權限),您可以直接載入物件,而無需設定 config 參數。

loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint)
loader.load()

此頁面是否對您有所幫助?