Skip to main content

EPUB 文件

¥EPUB files

本示例介绍如何从 EPUB 文件加载数据。默认情况下,EPUB 文件中的每个章节都会创建一个文档,你可以通过将 splitChapters 选项设置为 false 来更改此行为。

¥This example goes over how to load data from EPUB files. By default, one document will be created for each chapter in the EPUB file, you can change this behavior by setting the splitChapters option to false.

设置

¥Setup

npm install @langchain/community @langchain/core epub2 html-to-text

用法,一个每章一个文档

¥Usage, one document per chapter

import { EPubLoader } from "@langchain/community/document_loaders/fs/epub";

const loader = new EPubLoader("src/document_loaders/example_data/example.epub");

const docs = await loader.load();

用法,每个文件一个文档

¥Usage, one document per file

import { EPubLoader } from "@langchain/community/document_loaders/fs/epub";

const loader = new EPubLoader(
"src/document_loaders/example_data/example.epub",
{
splitChapters: false,
}
);

const docs = await loader.load();