华为 OBS 目录
The following code demonstrates how to load objects from the Huawei OBS (Object Storage Service) as documents.
# 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
如果您在华为云ECS上部署了langchain并且设置了代理,加载器可以直接从ECS获取安全令牌而无需使用访问密钥和秘密密钥。
config = {"get_token_from_ecs": True}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()
使用公共桶
如果您的桶的桶策略允许匿名访问(匿名用户具有listBucket和GetObject权限),您可以直接加载对象,无需配置config参数。
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint)
loader.load()