Skip to main content
Open In Colab在 GitHub 上打开

华为 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 上,并且设置了 Agency,则 loader 可以直接从 ECS 获取安全令牌,而无需访问 Key 和 Secret Key。

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()