Skip to main content

S3 文件

¥S3 File

Compatibility

仅在 Node.js 上可用。

¥Only available on Node.js.

本教程介绍如何从 S3 文件对象加载文档对象。

¥This covers how to load document objects from an s3 file object.

设置

¥Setup

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

¥To run this index 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.

你还需要安装官方 AWS SDK:

¥You'll also need to install the official AWS SDK:

npm install @langchain/community @langchain/core @aws-sdk/client-s3

用法

¥Usage

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

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

你可以选择提供 s3Config 参数来指定存储桶区域、访问密钥和秘密访问密钥。如果未提供这些,你需要在你的环境中安装它们(例如,通过运行 aws configure)。

¥You can optionally provide a s3Config parameter to specify your bucket region, access key, and secret access key. If these are not provided, you will need to have them in your environment (e.g., by running aws configure).

import { S3Loader } from "@langchain/community/document_loaders/web/s3";

const loader = new S3Loader({
bucket: "my-document-bucket-123",
key: "AccountingOverview.pdf",
s3Config: {
region: "us-east-1",
credentials: {
accessKeyId: "AKIAIOSFODNN7EXAMPLE",
secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
},
},
unstructuredAPIURL: "http://localhost:8000/general/v0/general",
unstructuredAPIKey: "", // this will be soon required
});

const docs = await loader.load();

console.log(docs);

API Reference:

  • S3Loader from @langchain/community/document_loaders/web/s3