mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-22 09:01:09 +03:00
add multi options
This commit is contained in:
@@ -45,6 +45,66 @@ class UnstructuredFile_DocumentLoaders implements INode {
|
||||
type: 'string',
|
||||
default: 'http://localhost:8000/general/v0/general'
|
||||
},
|
||||
{
|
||||
label: 'Element Type',
|
||||
name: 'elementType',
|
||||
description:
|
||||
'Unstructured partition document into different types, select the types to return. If not selected, all types will be returned',
|
||||
type: 'multiOptions',
|
||||
options: [
|
||||
{
|
||||
label: 'FigureCaption',
|
||||
name: 'FigureCaption'
|
||||
},
|
||||
{
|
||||
label: 'NarrativeText',
|
||||
name: 'NarrativeText'
|
||||
},
|
||||
{
|
||||
label: 'ListItem',
|
||||
name: 'ListItem'
|
||||
},
|
||||
{
|
||||
label: 'Title',
|
||||
name: 'Title'
|
||||
},
|
||||
{
|
||||
label: 'Address',
|
||||
name: 'Address'
|
||||
},
|
||||
{
|
||||
label: 'Table',
|
||||
name: 'Table'
|
||||
},
|
||||
{
|
||||
label: 'PageBreak',
|
||||
name: 'PageBreak'
|
||||
},
|
||||
{
|
||||
label: 'Header',
|
||||
name: 'Header'
|
||||
},
|
||||
{
|
||||
label: 'Footer',
|
||||
name: 'Footer'
|
||||
},
|
||||
{
|
||||
label: 'UncategorizedText',
|
||||
name: 'UncategorizedText'
|
||||
},
|
||||
{
|
||||
label: 'Image',
|
||||
name: 'Image'
|
||||
},
|
||||
{
|
||||
label: 'Formula',
|
||||
name: 'Formula'
|
||||
}
|
||||
],
|
||||
default: [],
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
},
|
||||
{
|
||||
label: 'Metadata',
|
||||
name: 'metadata',
|
||||
@@ -52,13 +112,13 @@ class UnstructuredFile_DocumentLoaders implements INode {
|
||||
optional: true,
|
||||
additionalParams: true
|
||||
}
|
||||
/*TODO Add Filter Options*/
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const filePath = nodeData.inputs?.filePath as string
|
||||
const unstructuredAPIUrl = nodeData.inputs?.unstructuredAPIUrl as string
|
||||
const elementType = nodeData.inputs?.elementType as string
|
||||
const metadata = nodeData.inputs?.metadata
|
||||
|
||||
const obj: UnstructuredLoaderOptions = { apiUrl: unstructuredAPIUrl }
|
||||
@@ -70,6 +130,15 @@ class UnstructuredFile_DocumentLoaders implements INode {
|
||||
const loader = new UnstructuredLoader(filePath, obj)
|
||||
const docs = await loader.load()
|
||||
|
||||
let elementTypes: string[] = []
|
||||
if (elementType) {
|
||||
try {
|
||||
elementTypes = JSON.parse(elementType)
|
||||
} catch (e) {
|
||||
elementTypes = []
|
||||
}
|
||||
}
|
||||
|
||||
if (metadata) {
|
||||
const parsedMetadata = typeof metadata === 'object' ? metadata : JSON.parse(metadata)
|
||||
let finaldocs = []
|
||||
@@ -83,10 +152,10 @@ class UnstructuredFile_DocumentLoaders implements INode {
|
||||
}
|
||||
finaldocs.push(newdoc)
|
||||
}
|
||||
return finaldocs
|
||||
return elementTypes.length ? finaldocs.filter((doc) => elementTypes.includes(doc.metadata.category)) : finaldocs
|
||||
}
|
||||
|
||||
return docs
|
||||
return elementTypes.length ? docs.filter((doc) => elementTypes.includes(doc.metadata.category)) : docs
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user