Skip to main content

Google 云端存储

¥Google Cloud Storage

Compatibility

仅在 Node.js 上可用。

¥Only available on Node.js.

本概述介绍如何将 Google Cloud Storage 文件加载到 LangChain 文档中。

¥This covers how to load a Google Cloud Storage File into LangChain documents.

设置

¥Setup

要使用此加载器,你需要已设置好 Unstructured 并准备好在可用的 URL 端点上使用。它也可以配置为本地运行。

¥To use this loader, you'll need to have Unstructured already set up and ready to use at an available URL endpoint. It can also be configured to run locally.

查看 此处 文档,了解如何执行此操作。

¥See the docs here for information on how to do that.

你还需要安装官方 Google Cloud Storage SDK:

¥You'll also need to install the official Google Cloud Storage SDK:

npm install @langchain/community @langchain/core @google-cloud/storage

用法

¥Usage

配置非结构化文件后,你可以使用 Google Cloud Storage 加载器加载文件,然后将其转换为文档。

¥Once Unstructured is configured, you can use the Google Cloud Storage loader to load files and then convert them into a Document.

此外,如果你不想将应用默认凭据 (ADC) 作为默认方式,你可以选择提供一个 storageOptions 参数来指定存储选项以及其他身份验证方式。

¥In addition, you can optionally provide a storageOptions parameter to specify not only your storage options but also other authentication ways if you don't want Application Default Credentials(ADC) as default manner.

import { GoogleCloudStorageLoader } from "@langchain/community/document_loaders/web/google_cloud_storage";

const loader = new GoogleCloudStorageLoader({
bucket: "my-bucket-123",
file: "path/to/file.pdf",
storageOptions: {
keyFilename: "/path/to/keyfile.json",
},
unstructuredLoaderOptions: {
apiUrl: "http://localhost:8000/general/v0/general",
apiKey: "", // this will be soon required
},
});

const docs = await loader.load();

console.log(docs);

API Reference: