From 0478fc96491b9b88d37623b8d091a2c147c10a7a Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Mon, 26 May 2025 15:57:34 +0800 Subject: [PATCH] datasource node variable --- .../rag-pipeline/hooks/use-pipeline-config.ts | 9 +++--- .../workflow/block-selector/tools.tsx | 1 - .../workflow/nodes/data-source/constants.ts | 30 ++++++++++++------- .../workflow/nodes/data-source/default.ts | 10 ++----- .../workflow/nodes/data-source/panel.tsx | 9 ++++-- .../nodes/knowledge-base/hooks/use-config.ts | 16 ++++++++-- web/service/use-pipeline.ts | 8 ++--- 7 files changed, 51 insertions(+), 32 deletions(-) diff --git a/web/app/components/rag-pipeline/hooks/use-pipeline-config.ts b/web/app/components/rag-pipeline/hooks/use-pipeline-config.ts index fa5fdc5905..dd5a5cf45b 100644 --- a/web/app/components/rag-pipeline/hooks/use-pipeline-config.ts +++ b/web/app/components/rag-pipeline/hooks/use-pipeline-config.ts @@ -6,7 +6,7 @@ import { import { useWorkflowConfig } from '@/service/use-workflow' import type { FetchWorkflowDraftResponse } from '@/types/workflow' import { useDataSourceList } from '@/service/use-pipeline' -import type { ToolWithProvider } from '@/app/components/workflow/types' +import type { DataSourceItem } from '@/app/components/workflow/block-selector/types' import { basePath } from '@/utils/var' export const usePipelineConfig = () => { @@ -43,10 +43,11 @@ export const usePipelineConfig = () => { handleUpdatePublishedAt, ) - const handleUpdateDataSourceList = useCallback((dataSourceList: ToolWithProvider[]) => { + const handleUpdateDataSourceList = useCallback((dataSourceList: DataSourceItem[]) => { dataSourceList.forEach((item) => { - if (typeof item.icon == 'string' && !item.icon.includes(basePath)) - item.icon = `${basePath}${item.icon}` + const icon = item.declaration.identity.icon + if (typeof icon == 'string' && !icon.includes(basePath)) + item.declaration.identity.icon = `${basePath}${icon}` }) const { setDataSourceList } = workflowStore.getState() setDataSourceList!(dataSourceList) diff --git a/web/app/components/workflow/block-selector/tools.tsx b/web/app/components/workflow/block-selector/tools.tsx index 6d833b02c2..2562501524 100644 --- a/web/app/components/workflow/block-selector/tools.tsx +++ b/web/app/components/workflow/block-selector/tools.tsx @@ -55,7 +55,6 @@ const Blocks = ({ } } */ - console.log(tools, 'tools') const { letters, groups: withLetterAndGroupViewToolsData } = groupItems(tools, tool => tool.label[language][0]) const treeViewToolsData = useMemo(() => { const result: Record = {} diff --git a/web/app/components/workflow/nodes/data-source/constants.ts b/web/app/components/workflow/nodes/data-source/constants.ts index 777f4689a8..9d6392141e 100644 --- a/web/app/components/workflow/nodes/data-source/constants.ts +++ b/web/app/components/workflow/nodes/data-source/constants.ts @@ -11,16 +11,6 @@ export const OUTPUT_VARIABLES_MAP = { type: VarType.file, description: 'file', subItems: [ - { - name: 'type', - type: VarType.string, - description: '', - }, - { - name: 'upload_file_id', - type: VarType.string, - description: '', - }, { name: 'name', type: VarType.string, @@ -31,6 +21,11 @@ export const OUTPUT_VARIABLES_MAP = { type: VarType.number, description: '', }, + { + name: 'type', + type: VarType.string, + description: '', + }, { name: 'extension', type: VarType.string, @@ -41,6 +36,21 @@ export const OUTPUT_VARIABLES_MAP = { type: VarType.string, description: '', }, + { + name: 'transfer_method', + type: VarType.string, + description: '', + }, + { + name: 'url', + type: VarType.string, + description: '', + }, + { + name: 'related_id', + type: VarType.string, + description: '', + }, ], }, } diff --git a/web/app/components/workflow/nodes/data-source/default.ts b/web/app/components/workflow/nodes/data-source/default.ts index 23ad741998..8608aa314c 100644 --- a/web/app/components/workflow/nodes/data-source/default.ts +++ b/web/app/components/workflow/nodes/data-source/default.ts @@ -22,8 +22,8 @@ const nodeDefault: NodeDefault = { } }, getOutputVars(payload) { - const { provider_id, provider_type } = payload - const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource + const { datasource_name, provider_type } = payload + const isLocalFile = datasource_name === 'local_file' && provider_type === CollectionType.datasource return [ { variable: OUTPUT_VARIABLES_MAP.datasource_type.name, @@ -35,12 +35,6 @@ const nodeDefault: NodeDefault = { { variable: OUTPUT_VARIABLES_MAP.file.name, type: OUTPUT_VARIABLES_MAP.file.type, - children: OUTPUT_VARIABLES_MAP.file.subItems.map((item) => { - return { - variable: item.name, - type: item.type, - } - }), }, ] : [] diff --git a/web/app/components/workflow/nodes/data-source/panel.tsx b/web/app/components/workflow/nodes/data-source/panel.tsx index 513c811d9a..232726fe35 100644 --- a/web/app/components/workflow/nodes/data-source/panel.tsx +++ b/web/app/components/workflow/nodes/data-source/panel.tsx @@ -13,12 +13,12 @@ import { OUTPUT_VARIABLES_MAP } from './constants' const Panel: FC> = ({ id, data }) => { const { t } = useTranslation() const { - provider_id, provider_type, fileExtensions = [], + datasource_name, } = data const { handleFileExtensionsChange } = useConfig(id) - const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource + const isLocalFile = datasource_name === 'local_file' && provider_type === CollectionType.datasource return (
@@ -57,6 +57,11 @@ const Panel: FC> = ({ id, data }) => { name={OUTPUT_VARIABLES_MAP.file.name} type={OUTPUT_VARIABLES_MAP.file.type} description={OUTPUT_VARIABLES_MAP.file.description} + subItems={OUTPUT_VARIABLES_MAP.file.subItems.map(item => ({ + name: item.name, + type: item.type, + description: item.description, + }))} /> ) } diff --git a/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts b/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts index 670bde7418..97314797df 100644 --- a/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts +++ b/web/app/components/workflow/nodes/knowledge-base/hooks/use-config.ts @@ -1,18 +1,19 @@ import { useCallback, } from 'react' +import { produce } from 'immer' import { useStoreApi } from 'reactflow' import { useNodeDataUpdate } from '@/app/components/workflow/hooks' import type { ValueSelector } from '@/app/components/workflow/types' import { ChunkStructureEnum, IndexMethodEnum, + RetrievalSearchMethodEnum, } from '../types' import type { HybridSearchModeEnum, KnowledgeBaseNodeType, RerankingModel, - RetrievalSearchMethodEnum, } from '../types' export const useConfig = (id: string) => { @@ -43,8 +44,17 @@ export const useConfig = (id: string) => { }, [handleNodeDataUpdate, getNodeData]) const handleIndexMethodChange = useCallback((indexMethod: IndexMethodEnum) => { - handleNodeDataUpdate({ indexing_technique: indexMethod }) - }, [handleNodeDataUpdate]) + const nodeData = getNodeData() + + handleNodeDataUpdate(produce(nodeData?.data as KnowledgeBaseNodeType, (draft) => { + draft.indexing_technique = indexMethod + + if (indexMethod === IndexMethodEnum.ECONOMICAL) + draft.retrieval_model.search_method = RetrievalSearchMethodEnum.invertedIndex + else if (indexMethod === IndexMethodEnum.QUALIFIED) + draft.retrieval_model.search_method = RetrievalSearchMethodEnum.semantic + })) + }, [handleNodeDataUpdate, getNodeData]) const handleKeywordNumberChange = useCallback((keywordNumber: number) => { handleNodeDataUpdate({ keyword_number: keywordNumber }) diff --git a/web/service/use-pipeline.ts b/web/service/use-pipeline.ts index 9ab0697337..c0aebac2ef 100644 --- a/web/service/use-pipeline.ts +++ b/web/service/use-pipeline.ts @@ -19,7 +19,7 @@ import type { UpdateTemplateInfoRequest, UpdateTemplateInfoResponse, } from '@/models/pipeline' -import type { ToolWithProvider } from '@/app/components/workflow/types' +import type { DataSourceItem } from '@/app/components/workflow/block-selector/types' const NAME_SPACE = 'pipeline' @@ -161,12 +161,12 @@ export const usePublishedPipelineProcessingParams = (params: PipelineProcessingP }) } -export const useDataSourceList = (enabled: boolean, onSuccess: (v: ToolWithProvider[]) => void) => { - return useQuery({ +export const useDataSourceList = (enabled: boolean, onSuccess: (v: DataSourceItem[]) => void) => { + return useQuery({ enabled, queryKey: [NAME_SPACE, 'datasource'], queryFn: async () => { - const data = await get('/rag/pipelines/datasource-plugins') + const data = await get('/rag/pipelines/datasource-plugins') onSuccess(data) return data },