@n8n/n8n-nodes-langchain
Version:

175 lines • 6.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentBinaryInputLoader = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const ai_utilities_1 = require("@n8n/ai-utilities");
require("mammoth");
require("epub2");
require("pdf-parse");
class DocumentBinaryInputLoader {
constructor() {
this.description = {
hidden: true,
displayName: 'Binary Input Loader',
name: 'documentBinaryInputLoader',
icon: 'file:binary.svg',
group: ['transform'],
version: 1,
description: 'Use binary data from a previous step in the workflow',
defaults: {
name: 'Binary Input Loader',
},
codex: {
categories: ['AI'],
subcategories: {
AI: ['Document Loaders'],
},
resources: {
primaryDocumentation: [
{
url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.documentdefaultdataloader/',
},
],
},
},
inputs: [
{
displayName: 'Text Splitter',
maxConnections: 1,
type: n8n_workflow_1.NodeConnectionTypes.AiTextSplitter,
required: true,
},
],
outputs: [n8n_workflow_1.NodeConnectionTypes.AiDocument],
outputNames: ['Document'],
builderHint: {
inputs: {
ai_textSplitter: { required: true },
},
},
properties: [
(0, ai_utilities_1.getConnectionHintNoticeField)([n8n_workflow_1.NodeConnectionTypes.AiVectorStore]),
{
displayName: 'Loader Type',
name: 'loader',
type: 'options',
default: 'jsonLoader',
required: true,
options: [
{
name: 'CSV Loader',
value: 'csvLoader',
description: 'Load CSV files',
},
{
name: 'Docx Loader',
value: 'docxLoader',
description: 'Load Docx documents',
},
{
name: 'EPub Loader',
value: 'epubLoader',
description: 'Load EPub files',
},
{
name: 'JSON Loader',
value: 'jsonLoader',
description: 'Load JSON files',
},
{
name: 'PDF Loader',
value: 'pdfLoader',
description: 'Load PDF documents',
},
{
name: 'Text Loader',
value: 'textLoader',
description: 'Load plain text files',
},
],
},
{
displayName: 'Binary Data Key',
name: 'binaryDataKey',
type: 'string',
default: 'data',
required: true,
description: 'Name of the binary property from which to read the file buffer',
},
{
displayName: 'Split Pages',
name: 'splitPages',
type: 'boolean',
default: true,
displayOptions: {
show: {
loader: ['pdfLoader'],
},
},
},
{
displayName: 'Column',
name: 'column',
type: 'string',
default: '',
description: 'Column to extract from CSV',
displayOptions: {
show: {
loader: ['csvLoader'],
},
},
},
{
displayName: 'Separator',
name: 'separator',
type: 'string',
description: 'Separator to use for CSV',
default: ',',
displayOptions: {
show: {
loader: ['csvLoader'],
},
},
},
{
displayName: 'Pointers',
name: 'pointers',
type: 'string',
default: '',
description: 'Pointers to extract from JSON, e.g. "/text" or "/text, /meta/title"',
displayOptions: {
show: {
loader: ['jsonLoader'],
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
...ai_utilities_1.metadataFilterField,
displayName: 'Metadata',
description: 'Metadata to add to each document. Could be used for filtering during retrieval',
placeholder: 'Add property',
},
],
},
],
};
}
async supplyData() {
this.logger.debug('Supply Data for Binary Input Loader');
const textSplitter = (await this.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiTextSplitter, 0));
const binaryDataKey = this.getNodeParameter('binaryDataKey', 0);
const processor = new ai_utilities_1.N8nBinaryLoader(this, undefined, binaryDataKey, textSplitter);
return {
response: (0, ai_utilities_1.logWrapper)(processor, this),
};
}
}
exports.DocumentBinaryInputLoader = DocumentBinaryInputLoader;
//# sourceMappingURL=DocumentBinaryInputLoader.node.js.map