langcode
Version:
A Plugin-Based Framework for Managing and Using LangChain
37 lines (36 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("../../types");
const csv_1 = require("@langchain/community/document_loaders/fs/csv");
class CsvLoaderPlugin {
constructor() {
this.name = "csvLoader";
this.description = "Loads content from a CSV file.";
this.type = types_1.PluginType.Loader;
this.RunConfigExample = {};
this.InitConfigExample = {
path: "./example.csv",
};
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 csv_1.CSVLoader(config.path);
}
async run(args) {
if (!this.loader)
throw new Error("CSVLoader is not initialized.");
const docs = await this.loader.load();
return docs.map((d) => d.pageContent).join("\n");
}
}
exports.default = CsvLoaderPlugin;