datasource node variable

pull/21398/head
zxhlyh 1 year ago
parent b5f88c77a3
commit 0478fc9649

@ -6,7 +6,7 @@ import {
import { useWorkflowConfig } from '@/service/use-workflow' import { useWorkflowConfig } from '@/service/use-workflow'
import type { FetchWorkflowDraftResponse } from '@/types/workflow' import type { FetchWorkflowDraftResponse } from '@/types/workflow'
import { useDataSourceList } from '@/service/use-pipeline' 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' import { basePath } from '@/utils/var'
export const usePipelineConfig = () => { export const usePipelineConfig = () => {
@ -43,10 +43,11 @@ export const usePipelineConfig = () => {
handleUpdatePublishedAt, handleUpdatePublishedAt,
) )
const handleUpdateDataSourceList = useCallback((dataSourceList: ToolWithProvider[]) => { const handleUpdateDataSourceList = useCallback((dataSourceList: DataSourceItem[]) => {
dataSourceList.forEach((item) => { dataSourceList.forEach((item) => {
if (typeof item.icon == 'string' && !item.icon.includes(basePath)) const icon = item.declaration.identity.icon
item.icon = `${basePath}${item.icon}` if (typeof icon == 'string' && !icon.includes(basePath))
item.declaration.identity.icon = `${basePath}${icon}`
}) })
const { setDataSourceList } = workflowStore.getState() const { setDataSourceList } = workflowStore.getState()
setDataSourceList!(dataSourceList) setDataSourceList!(dataSourceList)

@ -55,7 +55,6 @@ const Blocks = ({
} }
} }
*/ */
console.log(tools, 'tools')
const { letters, groups: withLetterAndGroupViewToolsData } = groupItems(tools, tool => tool.label[language][0]) const { letters, groups: withLetterAndGroupViewToolsData } = groupItems(tools, tool => tool.label[language][0])
const treeViewToolsData = useMemo(() => { const treeViewToolsData = useMemo(() => {
const result: Record<string, ToolWithProvider[]> = {} const result: Record<string, ToolWithProvider[]> = {}

@ -11,33 +11,43 @@ export const OUTPUT_VARIABLES_MAP = {
type: VarType.file, type: VarType.file,
description: 'file', description: 'file',
subItems: [ subItems: [
{
name: 'name',
type: VarType.string,
description: '',
},
{
name: 'size',
type: VarType.number,
description: '',
},
{ {
name: 'type', name: 'type',
type: VarType.string, type: VarType.string,
description: '', description: '',
}, },
{ {
name: 'upload_file_id', name: 'extension',
type: VarType.string, type: VarType.string,
description: '', description: '',
}, },
{ {
name: 'name', name: 'mime_type',
type: VarType.string, type: VarType.string,
description: '', description: '',
}, },
{ {
name: 'size', name: 'transfer_method',
type: VarType.number, type: VarType.string,
description: '', description: '',
}, },
{ {
name: 'extension', name: 'url',
type: VarType.string, type: VarType.string,
description: '', description: '',
}, },
{ {
name: 'mime_type', name: 'related_id',
type: VarType.string, type: VarType.string,
description: '', description: '',
}, },

@ -22,8 +22,8 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
} }
}, },
getOutputVars(payload) { getOutputVars(payload) {
const { provider_id, provider_type } = payload const { datasource_name, provider_type } = payload
const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource const isLocalFile = datasource_name === 'local_file' && provider_type === CollectionType.datasource
return [ return [
{ {
variable: OUTPUT_VARIABLES_MAP.datasource_type.name, variable: OUTPUT_VARIABLES_MAP.datasource_type.name,
@ -35,12 +35,6 @@ const nodeDefault: NodeDefault<DataSourceNodeType> = {
{ {
variable: OUTPUT_VARIABLES_MAP.file.name, variable: OUTPUT_VARIABLES_MAP.file.name,
type: OUTPUT_VARIABLES_MAP.file.type, type: OUTPUT_VARIABLES_MAP.file.type,
children: OUTPUT_VARIABLES_MAP.file.subItems.map((item) => {
return {
variable: item.name,
type: item.type,
}
}),
}, },
] ]
: [] : []

@ -13,12 +13,12 @@ import { OUTPUT_VARIABLES_MAP } from './constants'
const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => { const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
const { t } = useTranslation() const { t } = useTranslation()
const { const {
provider_id,
provider_type, provider_type,
fileExtensions = [], fileExtensions = [],
datasource_name,
} = data } = data
const { handleFileExtensionsChange } = useConfig(id) 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 ( return (
<div > <div >
@ -57,6 +57,11 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
name={OUTPUT_VARIABLES_MAP.file.name} name={OUTPUT_VARIABLES_MAP.file.name}
type={OUTPUT_VARIABLES_MAP.file.type} type={OUTPUT_VARIABLES_MAP.file.type}
description={OUTPUT_VARIABLES_MAP.file.description} description={OUTPUT_VARIABLES_MAP.file.description}
subItems={OUTPUT_VARIABLES_MAP.file.subItems.map(item => ({
name: item.name,
type: item.type,
description: item.description,
}))}
/> />
) )
} }

@ -1,18 +1,19 @@
import { import {
useCallback, useCallback,
} from 'react' } from 'react'
import { produce } from 'immer'
import { useStoreApi } from 'reactflow' import { useStoreApi } from 'reactflow'
import { useNodeDataUpdate } from '@/app/components/workflow/hooks' import { useNodeDataUpdate } from '@/app/components/workflow/hooks'
import type { ValueSelector } from '@/app/components/workflow/types' import type { ValueSelector } from '@/app/components/workflow/types'
import { import {
ChunkStructureEnum, ChunkStructureEnum,
IndexMethodEnum, IndexMethodEnum,
RetrievalSearchMethodEnum,
} from '../types' } from '../types'
import type { import type {
HybridSearchModeEnum, HybridSearchModeEnum,
KnowledgeBaseNodeType, KnowledgeBaseNodeType,
RerankingModel, RerankingModel,
RetrievalSearchMethodEnum,
} from '../types' } from '../types'
export const useConfig = (id: string) => { export const useConfig = (id: string) => {
@ -43,8 +44,17 @@ export const useConfig = (id: string) => {
}, [handleNodeDataUpdate, getNodeData]) }, [handleNodeDataUpdate, getNodeData])
const handleIndexMethodChange = useCallback((indexMethod: IndexMethodEnum) => { const handleIndexMethodChange = useCallback((indexMethod: IndexMethodEnum) => {
handleNodeDataUpdate({ indexing_technique: indexMethod }) const nodeData = getNodeData()
}, [handleNodeDataUpdate])
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) => { const handleKeywordNumberChange = useCallback((keywordNumber: number) => {
handleNodeDataUpdate({ keyword_number: keywordNumber }) handleNodeDataUpdate({ keyword_number: keywordNumber })

@ -19,7 +19,7 @@ import type {
UpdateTemplateInfoRequest, UpdateTemplateInfoRequest,
UpdateTemplateInfoResponse, UpdateTemplateInfoResponse,
} from '@/models/pipeline' } 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' const NAME_SPACE = 'pipeline'
@ -161,12 +161,12 @@ export const usePublishedPipelineProcessingParams = (params: PipelineProcessingP
}) })
} }
export const useDataSourceList = (enabled: boolean, onSuccess: (v: ToolWithProvider[]) => void) => { export const useDataSourceList = (enabled: boolean, onSuccess: (v: DataSourceItem[]) => void) => {
return useQuery<ToolWithProvider[]>({ return useQuery<DataSourceItem[]>({
enabled, enabled,
queryKey: [NAME_SPACE, 'datasource'], queryKey: [NAME_SPACE, 'datasource'],
queryFn: async () => { queryFn: async () => {
const data = await get<ToolWithProvider[]>('/rag/pipelines/datasource-plugins') const data = await get<DataSourceItem[]>('/rag/pipelines/datasource-plugins')
onSuccess(data) onSuccess(data)
return data return data
}, },

Loading…
Cancel
Save