rag pipeline initial template

This commit is contained in:
zxhlyh 2025-08-27 14:39:39 +08:00
parent e1a2755e3b
commit ff33d42c55
5 changed files with 3 additions and 126 deletions

View File

@ -1,48 +1,14 @@
import { useTranslation } from 'react-i18next'
import { generateNewNode } from '@/app/components/workflow/utils'
import {
NODE_WIDTH_X_OFFSET,
START_INITIAL_POSITION,
} from '@/app/components/workflow/constants'
import type { KnowledgeBaseNodeType } from '@/app/components/workflow/nodes/knowledge-base/types'
import knowledgeBaseDefault from '@/app/components/workflow/nodes/knowledge-base/default'
import ToolNodeDefault from '@/app/components/workflow/nodes/tool/default'
export const usePipelineTemplate = () => {
const { t } = useTranslation()
const { newNode: difyExtractorNode } = generateNewNode({
id: 'difyExtractor',
data: {
...ToolNodeDefault.defaultValue,
type: ToolNodeDefault.metaData.type,
title: '',
provider_id: 'langgenius/dify_extractor/dify_extractor',
tool_name: 'dify_extractor',
_notInitialized: true,
},
position: {
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET,
y: START_INITIAL_POSITION.y,
},
} as any)
const { newNode: generalChunkNode } = generateNewNode({
id: 'generalChunk',
data: {
...ToolNodeDefault.defaultValue,
type: ToolNodeDefault.metaData.type,
title: '',
provider_id: 'langgenius/general_chunker/general_chunker',
tool_name: 'general_chunker',
_notInitialized: true,
},
position: {
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET * 2,
y: START_INITIAL_POSITION.y,
},
} as any)
const { newNode: knowledgeBaseNode } = generateNewNode({
id: 'knowledgeBase',
data: {
@ -51,29 +17,13 @@ export const usePipelineTemplate = () => {
title: t(`workflow.blocks.${knowledgeBaseDefault.metaData.type}`),
},
position: {
x: START_INITIAL_POSITION.x + NODE_WIDTH_X_OFFSET * 3,
x: START_INITIAL_POSITION.x + 500,
y: START_INITIAL_POSITION.y,
},
})
const difyExtractorToGeneralChunkEdge = {
id: `${difyExtractorNode.id}-${generalChunkNode.id}`,
source: difyExtractorNode.id,
sourceHandle: 'source',
target: generalChunkNode.id,
targetHandle: 'target',
}
const generalChunkToKnowledgeBaseEdge = {
id: `${generalChunkNode.id}-${knowledgeBaseNode.id}`,
source: generalChunkNode.id,
sourceHandle: 'source',
target: knowledgeBaseNode.id,
targetHandle: 'target',
}
return {
nodes: [difyExtractorNode, generalChunkNode, knowledgeBaseNode],
edges: [difyExtractorToGeneralChunkEdge, generalChunkToKnowledgeBaseEdge],
nodes: [knowledgeBaseNode],
edges: [],
}
}

View File

@ -3,15 +3,12 @@ import React from 'react'
import type { ToolNodeType } from './types'
import type { NodeProps } from '@/app/components/workflow/types'
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import { useInitial } from './use-initial'
const Node: FC<NodeProps<ToolNodeType>> = ({
id,
data,
}) => {
const { tool_configurations, paramSchemas } = data
const toolConfigs = Object.keys(tool_configurations || {})
useInitial(id)
if (!toolConfigs.length)
return null

View File

@ -12,7 +12,6 @@ import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/compo
import StructureOutputItem from '@/app/components/workflow/nodes/_base/components/variable/object-child-tree-panel/show'
import { useStore } from '@/app/components/workflow/store'
import { wrapStructuredVarItem } from '@/app/components/workflow/utils/tool'
import { useInitial } from './use-initial'
import useMatchSchemaType from '../_base/components/variable/use-match-schema-type'
const i18nPrefix = 'workflow.nodes.tool'
@ -22,7 +21,6 @@ const Panel: FC<NodePanelProps<ToolNodeType>> = ({
data,
}) => {
const { t } = useTranslation()
useInitial(id)
const {
readOnly,
inputs,

View File

@ -26,5 +26,4 @@ export type ToolNodeType = CommonNodeType & {
tool_description?: string
is_team_authorization?: boolean
params?: Record<string, any>
_notInitialized?: boolean
}

View File

@ -1,67 +0,0 @@
import {
useCallback,
useEffect,
} from 'react'
import { useStoreApi } from 'reactflow'
import { useNodeDataUpdate } from '@/app/components/workflow/hooks/use-node-data-update'
import { useLanguage } from '@/app/components/header/account-setting/model-provider-page/hooks'
import { useStore } from '../../store'
import type { ToolNodeType } from './types'
import { canFindTool } from '@/utils'
export const useInitial = (id: string) => {
const store = useStoreApi()
const buildInTools = useStore(s => s.buildInTools)
const language = useLanguage()
const { handleNodeDataUpdateWithSyncDraft } = useNodeDataUpdate()
const getNodeData = useCallback(() => {
const { getNodes } = store.getState()
const nodes = getNodes()
return nodes.find(node => node.id === id)
}, [store, id])
const handleNodeDataUpdate = useCallback((data: Partial<ToolNodeType>) => {
handleNodeDataUpdateWithSyncDraft({
id,
data,
})
}, [id, handleNodeDataUpdateWithSyncDraft])
const handleInitial = useCallback(() => {
const nodeData = getNodeData()
const { provider_id, tool_name, _notInitialized } = nodeData?.data || {}
const currCollection = buildInTools.find(item => canFindTool(item.id, provider_id))
const currTool = currCollection?.tools.find(tool => tool.name === tool_name)
if (!currTool)
return
if (_notInitialized && currCollection) {
const params: Record<string, string> = {}
if (currTool.parameters) {
currTool.parameters.forEach((item) => {
params[item.name] = ''
})
}
handleNodeDataUpdate({
provider_id: currCollection.id,
provider_type: currCollection.type as any,
provider_name: currCollection.name,
tool_name: currTool.name,
tool_label: currTool.label[language],
tool_description: currTool.description[language],
title: currTool.label[language],
is_team_authorization: currCollection.is_team_authorization,
paramSchemas: currTool.parameters,
params,
_notInitialized: false,
})
}
}, [handleNodeDataUpdate, language, buildInTools, getNodeData])
useEffect(() => {
handleInitial()
}, [handleInitial])
}