Skip to main content

华为OBS目录 (Huawei OBS Directory)

The following code demonstrates how to load objects from the Huawei OBS (Object Storage Service) as documents.

以下代码演示了如何从华为OBS(对象存储服务)加载对象作为文档。

# 安装所需的包
# pip install esdk-obs-python
from langchain.document_loaders import OBSDirectoryLoader
endpoint = "your-endpoint"
# 配置访问凭证
config = {
"ak": "your-access-key",
"sk": "your-secret-key"
}
loader = OBSDirectoryLoader("your-bucket-name", endpoint=endpoint, config=config)
loader.load()

指定加载的前缀 (Specify a Prefix for Loading)

If you want to load objects with a specific prefix from the bucket, you can use the following code:

如果您想从存储桶中加载具有特定前缀的对象,可以使用以下代码:

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

从ECS获取认证信息 (Get Authentication Information from ECS)

If your langchain is deployed on Huawei Cloud ECS and Agency is set up, the loader can directly get the security token from ECS without needing access key and secret key.

如果您的langchain部署在华为云ECS上,并且已设置了代理,加载器可以直接从ECS获取安全令牌,而无需访问密钥和秘密密钥。

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

使用公共存储桶 (Use a Public Bucket)

If your bucket's bucket policy allows anonymous access (anonymous users have listBucket and GetObject permissions), you can directly load the objects without configuring the config parameter.

如果您的存储桶的存储桶策略允许匿名访问(匿名用户具有listBucketGetObject权限),您可以直接加载对象,而无需配置config参数。

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