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,8 +60,11 @@ 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(
folderPath,
{
'.json': (path) => new JSONLoader(path), '.json': (path) => new JSONLoader(path),
'.txt': (path) => new TextLoader(path), '.txt': (path) => new TextLoader(path),
'.csv': (path) => new CSVLoader(path), '.csv': (path) => new CSVLoader(path),
@@ -96,7 +105,9 @@ class Folder_DocumentLoaders implements INode {
'.html': (path) => new TextLoader(path), // HTML '.html': (path) => new TextLoader(path), // HTML
'.vb': (path) => new TextLoader(path), // Visual Basic '.vb': (path) => new TextLoader(path), // Visual Basic
'.xml': (path) => new TextLoader(path) // XML '.xml': (path) => new TextLoader(path) // XML
}) },
recursive
)
let docs = [] let docs = []
if (textSplitter) { if (textSplitter) {