Merge pull request #1688 from ill-yes/bugfix/folder_recursive

add recursive option for folder-loader
This commit is contained in:
Henry Heng
2024-02-07 01:39:19 +08:00
committed by GitHub
@@ -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,54 @@ 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, { const loader = new DirectoryLoader(
'.json': (path) => new JSONLoader(path), folderPath,
'.txt': (path) => new TextLoader(path), {
'.csv': (path) => new CSVLoader(path), '.json': (path) => new JSONLoader(path),
'.docx': (path) => new DocxLoader(path), '.txt': (path) => new TextLoader(path),
// @ts-ignore '.csv': (path) => new CSVLoader(path),
'.pdf': (path) => new PDFLoader(path, { pdfjs: () => import('pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js') }), '.docx': (path) => new DocxLoader(path),
'.aspx': (path) => new TextLoader(path), // @ts-ignore
'.asp': (path) => new TextLoader(path), '.pdf': (path) => new PDFLoader(path, { pdfjs: () => import('pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js') }),
'.cpp': (path) => new TextLoader(path), // C++ '.aspx': (path) => new TextLoader(path),
'.c': (path) => new TextLoader(path), '.asp': (path) => new TextLoader(path),
'.cs': (path) => new TextLoader(path), '.cpp': (path) => new TextLoader(path), // C++
'.css': (path) => new TextLoader(path), '.c': (path) => new TextLoader(path),
'.go': (path) => new TextLoader(path), // Go '.cs': (path) => new TextLoader(path),
'.h': (path) => new TextLoader(path), // C++ Header files '.css': (path) => new TextLoader(path),
'.kt': (path) => new TextLoader(path), // Kotlin '.go': (path) => new TextLoader(path), // Go
'.java': (path) => new TextLoader(path), // Java '.h': (path) => new TextLoader(path), // C++ Header files
'.js': (path) => new TextLoader(path), // JavaScript '.kt': (path) => new TextLoader(path), // Kotlin
'.less': (path) => new TextLoader(path), // Less files '.java': (path) => new TextLoader(path), // Java
'.ts': (path) => new TextLoader(path), // TypeScript '.js': (path) => new TextLoader(path), // JavaScript
'.php': (path) => new TextLoader(path), // PHP '.less': (path) => new TextLoader(path), // Less files
'.proto': (path) => new TextLoader(path), // Protocol Buffers '.ts': (path) => new TextLoader(path), // TypeScript
'.python': (path) => new TextLoader(path), // Python '.php': (path) => new TextLoader(path), // PHP
'.py': (path) => new TextLoader(path), // Python '.proto': (path) => new TextLoader(path), // Protocol Buffers
'.rst': (path) => new TextLoader(path), // reStructuredText '.python': (path) => new TextLoader(path), // Python
'.ruby': (path) => new TextLoader(path), // Ruby '.py': (path) => new TextLoader(path), // Python
'.rb': (path) => new TextLoader(path), // Ruby '.rst': (path) => new TextLoader(path), // reStructuredText
'.rs': (path) => new TextLoader(path), // Rust '.ruby': (path) => new TextLoader(path), // Ruby
'.scala': (path) => new TextLoader(path), // Scala '.rb': (path) => new TextLoader(path), // Ruby
'.sc': (path) => new TextLoader(path), // Scala '.rs': (path) => new TextLoader(path), // Rust
'.scss': (path) => new TextLoader(path), // Sass '.scala': (path) => new TextLoader(path), // Scala
'.sol': (path) => new TextLoader(path), // Solidity '.sc': (path) => new TextLoader(path), // Scala
'.sql': (path) => new TextLoader(path), //SQL '.scss': (path) => new TextLoader(path), // Sass
'.swift': (path) => new TextLoader(path), // Swift '.sol': (path) => new TextLoader(path), // Solidity
'.markdown': (path) => new TextLoader(path), // Markdown '.sql': (path) => new TextLoader(path), //SQL
'.md': (path) => new TextLoader(path), // Markdown '.swift': (path) => new TextLoader(path), // Swift
'.tex': (path) => new TextLoader(path), // LaTeX '.markdown': (path) => new TextLoader(path), // Markdown
'.ltx': (path) => new TextLoader(path), // LaTeX '.md': (path) => new TextLoader(path), // Markdown
'.html': (path) => new TextLoader(path), // HTML '.tex': (path) => new TextLoader(path), // LaTeX
'.vb': (path) => new TextLoader(path), // Visual Basic '.ltx': (path) => new TextLoader(path), // LaTeX
'.xml': (path) => new TextLoader(path) // XML '.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) {