mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 02:35:56 +08:00
feat: doc extract support both file and file array
This commit is contained in:
parent
099746dd59
commit
5544791031
@ -15,6 +15,7 @@ import type { ParameterExtractorNodeType } from '../../../parameter-extractor/ty
|
|||||||
import type { IterationNodeType } from '../../../iteration/types'
|
import type { IterationNodeType } from '../../../iteration/types'
|
||||||
import type { ListFilterNodeType } from '../../../list-filter/types'
|
import type { ListFilterNodeType } from '../../../list-filter/types'
|
||||||
import { OUTPUT_FILE_SUB_VARIABLES } from '../../../if-else/default'
|
import { OUTPUT_FILE_SUB_VARIABLES } from '../../../if-else/default'
|
||||||
|
import type { DocExtractorNodeType } from '../../../document-extractor/types'
|
||||||
import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types'
|
import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types'
|
||||||
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
|
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
|
||||||
import type { ConversationVariable, EnvironmentVariable, Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
import type { ConversationVariable, EnvironmentVariable, Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
@ -252,7 +253,7 @@ const formatItem = (
|
|||||||
res.vars = [
|
res.vars = [
|
||||||
{
|
{
|
||||||
variable: 'text',
|
variable: 'text',
|
||||||
type: VarType.string,
|
type: (data as DocExtractorNodeType).is_array_file ? VarType.arrayString : VarType.string,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
break
|
break
|
||||||
|
@ -7,6 +7,7 @@ const i18nPrefix = 'workflow.errorMsg'
|
|||||||
const nodeDefault: NodeDefault<DocExtractorNodeType> = {
|
const nodeDefault: NodeDefault<DocExtractorNodeType> = {
|
||||||
defaultValue: {
|
defaultValue: {
|
||||||
variable_selector: [],
|
variable_selector: [],
|
||||||
|
is_array_file: false,
|
||||||
},
|
},
|
||||||
getAvailablePrevNodes(isChatMode: boolean) {
|
getAvailablePrevNodes(isChatMode: boolean) {
|
||||||
const nodes = isChatMode
|
const nodes = isChatMode
|
||||||
|
@ -2,4 +2,5 @@ import type { CommonNodeType, ValueSelector } from '@/app/components/workflow/ty
|
|||||||
|
|
||||||
export type DocExtractorNodeType = CommonNodeType & {
|
export type DocExtractorNodeType = CommonNodeType & {
|
||||||
variable_selector: ValueSelector
|
variable_selector: ValueSelector
|
||||||
|
is_array_file: boolean
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,59 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback, useMemo } from 'react'
|
||||||
import produce from 'immer'
|
import produce from 'immer'
|
||||||
|
import { useStoreApi } from 'reactflow'
|
||||||
|
|
||||||
import type { ValueSelector, Var } from '../../types'
|
import type { ValueSelector, Var } from '../../types'
|
||||||
import { VarType } from '../../types'
|
import { VarType } from '../../types'
|
||||||
import { type DocExtractorNodeType } from './types'
|
import { type DocExtractorNodeType } from './types'
|
||||||
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
|
||||||
import {
|
import {
|
||||||
|
useIsChatMode,
|
||||||
useNodesReadOnly,
|
useNodesReadOnly,
|
||||||
|
useWorkflow,
|
||||||
|
useWorkflowVariables,
|
||||||
} from '@/app/components/workflow/hooks'
|
} from '@/app/components/workflow/hooks'
|
||||||
|
|
||||||
const useConfig = (id: string, payload: DocExtractorNodeType) => {
|
const useConfig = (id: string, payload: DocExtractorNodeType) => {
|
||||||
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
const { nodesReadOnly: readOnly } = useNodesReadOnly()
|
||||||
|
|
||||||
const { inputs, setInputs } = useNodeCrud<DocExtractorNodeType>(id, payload)
|
const { inputs, setInputs } = useNodeCrud<DocExtractorNodeType>(id, payload)
|
||||||
|
|
||||||
|
const filterVar = useCallback((varPayload: Var) => {
|
||||||
|
return varPayload.type === VarType.file || varPayload.type === VarType.arrayFile
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const isChatMode = useIsChatMode()
|
||||||
|
|
||||||
|
const store = useStoreApi()
|
||||||
|
const { getBeforeNodesInSameBranch } = useWorkflow()
|
||||||
|
const {
|
||||||
|
getNodes,
|
||||||
|
} = store.getState()
|
||||||
|
const currentNode = getNodes().find(n => n.id === id)
|
||||||
|
const isInIteration = payload.isInIteration
|
||||||
|
const iterationNode = isInIteration ? getNodes().find(n => n.id === currentNode!.parentId) : null
|
||||||
|
const availableNodes = useMemo(() => {
|
||||||
|
return getBeforeNodesInSameBranch(id)
|
||||||
|
}, [getBeforeNodesInSameBranch, id])
|
||||||
|
|
||||||
|
const { getCurrentVariableType } = useWorkflowVariables()
|
||||||
|
const getType = useCallback((variable?: ValueSelector) => {
|
||||||
|
const varType = getCurrentVariableType({
|
||||||
|
parentNode: iterationNode,
|
||||||
|
valueSelector: variable || [],
|
||||||
|
availableNodes,
|
||||||
|
isChatMode,
|
||||||
|
isConstant: false,
|
||||||
|
})
|
||||||
|
return varType
|
||||||
|
}, [getCurrentVariableType, availableNodes, isChatMode, iterationNode])
|
||||||
|
|
||||||
const handleVarChanges = useCallback((variable: ValueSelector | string) => {
|
const handleVarChanges = useCallback((variable: ValueSelector | string) => {
|
||||||
const newInputs = produce(inputs, (draft) => {
|
const newInputs = produce(inputs, (draft) => {
|
||||||
draft.variable_selector = variable as ValueSelector
|
draft.variable_selector = variable as ValueSelector
|
||||||
|
draft.is_array_file = getType(draft.variable_selector) === VarType.arrayFile
|
||||||
})
|
})
|
||||||
setInputs(newInputs)
|
setInputs(newInputs)
|
||||||
}, [inputs, setInputs])
|
}, [getType, inputs, setInputs])
|
||||||
|
|
||||||
const filterVar = useCallback((varPayload: Var) => {
|
|
||||||
return varPayload.type === VarType.file
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
readOnly,
|
readOnly,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user