UNPKG

@jackhua/mini-langchain

Version:

A lightweight TypeScript implementation of LangChain with cost optimization features

35 lines 955 B
"use strict"; /** * Text document loader */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TextLoader = void 0; const promises_1 = require("fs/promises"); const base_1 = require("./base"); /** * Load text files */ class TextLoader extends base_1.BaseFileLoader { constructor(filePath, encoding = 'utf-8') { super(filePath); this.encoding = encoding; } async load() { try { const text = await (0, promises_1.readFile)(this.filePath, this.encoding); const metadata = { source: this.filePath, encoding: this.encoding }; return [{ pageContent: text, metadata }]; } catch (error) { throw new Error(`Failed to load file ${this.filePath}: ${error}`); } } } exports.TextLoader = TextLoader; //# sourceMappingURL=text.js.map