add recursive option for folder-loader

This commit is contained in:
Ilyes Tascou 2024-02-06 14:25:40 +01:00
parent 7faaf13ccc
commit 2bb2a7588a
1 changed files with 54 additions and 42 deletions

View File

@ -34,6 +34,12 @@ class Folder_DocumentLoaders implements INode {
type: 'string', type: 'string',
placeholder: '' placeholder: ''
}, },
{
label: 'Recursive',
name: 'recursive',
type: 'boolean',
additionalParams: false
},
{ {
label: 'Text Splitter', label: 'Text Splitter',
name: 'textSplitter', name: 'textSplitter',
@ -54,49 +60,55 @@ class Folder_DocumentLoaders implements INode {
const textSplitter = nodeData.inputs?.textSplitter as TextSplitter const textSplitter = nodeData.inputs?.textSplitter as TextSplitter
const folderPath = nodeData.inputs?.folderPath as string const folderPath = nodeData.inputs?.folderPath as string
const metadata = nodeData.inputs?.metadata const metadata = nodeData.inputs?.metadata
const recursive = nodeData.inputs?.recursive as boolean
const loader = new DirectoryLoader(folderPath, { console.log('Recursive: ', recursive)
'.json': (path) => new JSONLoader(path), const loader = new DirectoryLoader(
'.txt': (path) => new TextLoader(path), folderPath,
'.csv': (path) => new CSVLoader(path), {
'.docx': (path) => new DocxLoader(path), '.json': (path) => new JSONLoader(path),
// @ts-ignore '.txt': (path) => new TextLoader(path),
'.pdf': (path) => new PDFLoader(path, { pdfjs: () => import('pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js') }), '.csv': (path) => new CSVLoader(path),
'.aspx': (path) => new TextLoader(path), '.docx': (path) => new DocxLoader(path),
'.asp': (path) => new TextLoader(path), // @ts-ignore
'.cpp': (path) => new TextLoader(path), // C++ '.pdf': (path) => new PDFLoader(path, { pdfjs: () => import('pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js') }),
'.c': (path) => new TextLoader(path), '.aspx': (path) => new TextLoader(path),
'.cs': (path) => new TextLoader(path), '.asp': (path) => new TextLoader(path),
'.css': (path) => new TextLoader(path), '.cpp': (path) => new TextLoader(path), // C++
'.go': (path) => new TextLoader(path), // Go '.c': (path) => new TextLoader(path),
'.h': (path) => new TextLoader(path), // C++ Header files '.cs': (path) => new TextLoader(path),
'.kt': (path) => new TextLoader(path), // Kotlin '.css': (path) => new TextLoader(path),
'.java': (path) => new TextLoader(path), // Java '.go': (path) => new TextLoader(path), // Go
'.js': (path) => new TextLoader(path), // JavaScript '.h': (path) => new TextLoader(path), // C++ Header files
'.less': (path) => new TextLoader(path), // Less files '.kt': (path) => new TextLoader(path), // Kotlin
'.ts': (path) => new TextLoader(path), // TypeScript '.java': (path) => new TextLoader(path), // Java
'.php': (path) => new TextLoader(path), // PHP '.js': (path) => new TextLoader(path), // JavaScript
'.proto': (path) => new TextLoader(path), // Protocol Buffers '.less': (path) => new TextLoader(path), // Less files
'.python': (path) => new TextLoader(path), // Python '.ts': (path) => new TextLoader(path), // TypeScript
'.py': (path) => new TextLoader(path), // Python '.php': (path) => new TextLoader(path), // PHP
'.rst': (path) => new TextLoader(path), // reStructuredText '.proto': (path) => new TextLoader(path), // Protocol Buffers
'.ruby': (path) => new TextLoader(path), // Ruby '.python': (path) => new TextLoader(path), // Python
'.rb': (path) => new TextLoader(path), // Ruby '.py': (path) => new TextLoader(path), // Python
'.rs': (path) => new TextLoader(path), // Rust '.rst': (path) => new TextLoader(path), // reStructuredText
'.scala': (path) => new TextLoader(path), // Scala '.ruby': (path) => new TextLoader(path), // Ruby
'.sc': (path) => new TextLoader(path), // Scala '.rb': (path) => new TextLoader(path), // Ruby
'.scss': (path) => new TextLoader(path), // Sass '.rs': (path) => new TextLoader(path), // Rust
'.sol': (path) => new TextLoader(path), // Solidity '.scala': (path) => new TextLoader(path), // Scala
'.sql': (path) => new TextLoader(path), //SQL '.sc': (path) => new TextLoader(path), // Scala
'.swift': (path) => new TextLoader(path), // Swift '.scss': (path) => new TextLoader(path), // Sass
'.markdown': (path) => new TextLoader(path), // Markdown '.sol': (path) => new TextLoader(path), // Solidity
'.md': (path) => new TextLoader(path), // Markdown '.sql': (path) => new TextLoader(path), //SQL
'.tex': (path) => new TextLoader(path), // LaTeX '.swift': (path) => new TextLoader(path), // Swift
'.ltx': (path) => new TextLoader(path), // LaTeX '.markdown': (path) => new TextLoader(path), // Markdown
'.html': (path) => new TextLoader(path), // HTML '.md': (path) => new TextLoader(path), // Markdown
'.vb': (path) => new TextLoader(path), // Visual Basic '.tex': (path) => new TextLoader(path), // LaTeX
'.xml': (path) => new TextLoader(path) // XML '.ltx': (path) => new TextLoader(path), // LaTeX
}) '.html': (path) => new TextLoader(path), // HTML
'.vb': (path) => new TextLoader(path), // Visual Basic
'.xml': (path) => new TextLoader(path) // XML
},
recursive
)
let docs = [] let docs = []
if (textSplitter) { if (textSplitter) {