Google Cloud Storage
兼容性
仅在 Node.js 上可用。
本文介绍如何将 Google Cloud Storage 文件加载到 LangChain 文档中。
设置
要使用此加载器,您需要先设置 Unstructured,并使其在可用的 URL 端点准备就绪。它也可以配置为在本地运行。
请参阅此处的文档,了解如何操作。
您还需要安装官方的 Google Cloud Storage SDK
- npm
- Yarn
- pnpm
npm install @langchain/community @langchain/core @google-cloud/storage
yarn add @langchain/community @langchain/core @google-cloud/storage
pnpm add @langchain/community @langchain/core @google-cloud/storage
用法
配置 Unstructured 后,您可以使用 Google Cloud Storage 加载器加载文件,然后将其转换为文档。
此外,您可以选择提供 storageOptions
参数,不仅可以指定您的存储选项,还可以指定其他身份验证方式,如果您不想使用应用程序默认凭据 (ADC) 作为默认方式。
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 参考
- GoogleCloudStorageLoader 来自
@langchain/community/document_loaders/web/google_cloud_storage