UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

37 lines (36 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const text_1 = require("langchain/document_loaders/fs/text"); const types_1 = require("../../types"); class TextLoaderPlugin { constructor() { this.name = "textLoader"; this.description = "Loads plain text files from the file system."; this.type = types_1.PluginType.Loader; this.RunConfigExample = {}; this.InitConfigExample = { path: "./example.txt", }; this.loader = null; } expose() { return { name: this.name, description: this.description, type: this.type, InitConfigExample: this.InitConfigExample, RunConfigExample: this.RunConfigExample, loader: this.loader, }; } async init(config) { this.loader = new text_1.TextLoader(config.path); } async run(args) { if (!this.loader) throw new Error("TextLoader is not initialized."); const docs = await this.loader.load(); return docs.map((d) => d.pageContent).join("\n"); } } exports.default = TextLoaderPlugin;