Huawei OBS 檔案
The following code demonstrates how to load an object from the Huawei OBS (Object Storage Service) as document. (以下程式碼示範如何從華為 OBS (物件儲存服務) 載入物件作為文件。)
# Install the required package
# pip install esdk-obs-python
from langchain_community.document_loaders.obs_file import OBSFileLoader
endpoint = "your-endpoint"
from obs import ObsClient
obs_client = ObsClient(
access_key_id="your-access-key",
secret_access_key="your-secret-key",
server=endpoint,
)
loader = OBSFileLoader("your-bucket-name", "your-object-key", client=obs_client)
loader.load()
Each Loader with Separate Authentication Information (每個載入器使用不同的驗證資訊)
If you don't need to reuse OBS connections between different loaders, you can directly configure the config
. The loader will use the config information to initialize its own OBS client. (如果您不需要在不同的載入器之間重複使用 OBS 連線,您可以直接設定 config
。載入器將使用 config 資訊來初始化自己的 OBS 客戶端。)
# Configure your access credentials\n
config = {"ak": "your-access-key", "sk": "your-secret-key"}
loader = OBSFileLoader(
"your-bucket-name", "your-object-key", endpoint=endpoint, config=config
)
loader.load()
Get Authentication Information from ECS (從 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 上,並且已設定 Agency,載入器可以直接從 ECS 取得安全令牌,而無需存取金鑰和密碼。)
config = {"get_token_from_ecs": True}
loader = OBSFileLoader(
"your-bucket-name", "your-object-key", endpoint=endpoint, config=config
)
loader.load()
Access a Publicly Accessible Object (存取公開存取的物件)
If the object you want to access allows anonymous user access (anonymous users have GetObject
permission), you can directly load the object without configuring the config
parameter. (如果您要存取的物件允許匿名使用者存取 (匿名使用者具有 GetObject
權限),您可以直接載入該物件,而無需設定 config
參數。)
loader = OBSFileLoader("your-bucket-name", "your-object-key", endpoint=endpoint)
loader.load()
Related (相關資訊)
- Document loader conceptual guide (文件載入器概念指南)
- Document loader how-to guides (文件載入器操作指南)