datasource node variable

This commit is contained in:
zxhlyh 2025-05-26 15:57:34 +08:00
parent b5f88c77a3
commit 0478fc9649
7 changed files with 51 additions and 32 deletions

View File

@ -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)

View File

@ -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<string, ToolWithProvider[]> = {}

View File

@ -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: '',
},
],
},
}

View File

@ -22,8 +22,8 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
}
},
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<DataSourceNodeType> = {
{
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,
}
}),
},
]
: []

View File

@ -13,12 +13,12 @@ import { OUTPUT_VARIABLES_MAP } from './constants'
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ 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 (
<div >
@ -57,6 +57,11 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ 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,
}))}
/>
)
}

View File

@ -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 })

View File

@ -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<ToolWithProvider[]>({
export const useDataSourceList = (enabled: boolean, onSuccess: (v: DataSourceItem[]) => void) => {
return useQuery<DataSourceItem[]>({
enabled,
queryKey: [NAME_SPACE, 'datasource'],
queryFn: async () => {
const data = await get<ToolWithProvider[]>('/rag/pipelines/datasource-plugins')
const data = await get<DataSourceItem[]>('/rag/pipelines/datasource-plugins')
onSuccess(data)
return data
},