UNPKG

langcode

Version:

A Plugin-Based Framework for Managing and Using LangChain

46 lines (45 loc) 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../../types"); const directory_1 = require("langchain/document_loaders/fs/directory"); const text_1 = require("langchain/document_loaders/fs/text"); const pdf_1 = require("@langchain/community/document_loaders/fs/pdf"); const csv_1 = require("@langchain/community/document_loaders/fs/csv"); class DirectoryLoaderPlugin { constructor() { this.name = "directoryLoader"; this.description = "Loads all supported documents in a directory."; this.type = types_1.PluginType.Loader; this.RunConfigExample = {}; this.InitConfigExample = { directoryPath: "./veriler/", }; 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 directory_1.DirectoryLoader(config.directoryPath, { ".txt": (path) => new text_1.TextLoader(path), ".md": (path) => new text_1.TextLoader(path), ".csv": (path) => new csv_1.CSVLoader(path), ".pdf": (path) => new pdf_1.PDFLoader(path), ".json": (path) => new text_1.TextLoader(path), }); } async run(args) { if (!this.loader) throw new Error("DirectoryLoader not initialized."); const docs = await this.loader.load(); return docs.map((doc) => doc.pageContent).join("\n"); } } exports.default = DirectoryLoaderPlugin;