Skip to main content
以下代码演示了如何将华为 OBS(对象存储服务)中的对象加载为文档。
# Install the required package
# pip install esdk-obs-python
from langchain_community.document_loaders import 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()