Merge branch 'feat/rag-pipeline' of https://github.com/langgenius/dify into feat/rag-pipeline

pull/21398/head
twwu 11 months ago
commit 841bd35ebb

@ -38,6 +38,7 @@ const DataSources = ({
provider_name: toolDefaultValue?.provider_name, provider_name: toolDefaultValue?.provider_name,
datasource_name: toolDefaultValue?.tool_name, datasource_name: toolDefaultValue?.tool_name,
datasource_label: toolDefaultValue?.tool_label, datasource_label: toolDefaultValue?.tool_label,
title: toolDefaultValue?.title,
}) })
}, [onSelect]) }, [onSelect])

@ -33,6 +33,7 @@ import {
TEMPLATE_TRANSFORM_OUTPUT_STRUCT, TEMPLATE_TRANSFORM_OUTPUT_STRUCT,
TOOL_OUTPUT_STRUCT, TOOL_OUTPUT_STRUCT,
} from '@/app/components/workflow/constants' } from '@/app/components/workflow/constants'
import DataSourceNodeDefault from '@/app/components/workflow/nodes/data-source/default'
import type { PromptItem } from '@/models/debug' import type { PromptItem } from '@/models/debug'
import { VAR_REGEX } from '@/config' import { VAR_REGEX } from '@/config'
import type { AgentNodeType } from '../../../agent/types' import type { AgentNodeType } from '../../../agent/types'
@ -457,6 +458,11 @@ const formatItem = (
break break
} }
case BlockEnum.DataSource: {
res.vars = DataSourceNodeDefault.getOutputVars?.(data as any) || []
break
}
case 'env': { case 'env': {
res.vars = data.envList.map((env: EnvironmentVariable) => { res.vars = data.envList.map((env: EnvironmentVariable) => {
return { return {
@ -513,6 +519,8 @@ const formatItem = (
const isFile = v.type === VarType.file const isFile = v.type === VarType.file
const children = (() => { const children = (() => {
if (isFile) { if (isFile) {
if (v.children)
return v.children
return OUTPUT_FILE_SUB_VARIABLES.map((key) => { return OUTPUT_FILE_SUB_VARIABLES.map((key) => {
return { return {
variable: key, variable: key,
@ -529,9 +537,10 @@ const formatItem = (
return obj?.children && ((obj?.children as Var[]).length > 0 || Object.keys((obj?.children as StructuredOutput)?.schema?.properties || {}).length > 0) return obj?.children && ((obj?.children as Var[]).length > 0 || Object.keys((obj?.children as StructuredOutput)?.schema?.properties || {}).length > 0)
}).map((v) => { }).map((v) => {
const isFile = v.type === VarType.file const isFile = v.type === VarType.file
const { children } = (() => { const { children } = (() => {
if (isFile) { if (isFile) {
if (v.children)
return { children: v.children }
return { return {
children: OUTPUT_FILE_SUB_VARIABLES.map((key) => { children: OUTPUT_FILE_SUB_VARIABLES.map((key) => {
return { return {

@ -0,0 +1,46 @@
import { VarType } from '@/app/components/workflow/types'
export const OUTPUT_VARIABLES_MAP = {
datasource_type: {
name: 'datasource_type',
type: VarType.string,
description: 'local_file, online_document, website_crawl',
},
file: {
name: 'file',
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,
description: '',
},
{
name: 'size',
type: VarType.number,
description: '',
},
{
name: 'extension',
type: VarType.string,
description: '',
},
{
name: 'mime_type',
type: VarType.string,
description: '',
},
],
},
}

@ -2,6 +2,8 @@ import type { NodeDefault } from '../../types'
import type { DataSourceNodeType } from './types' import type { DataSourceNodeType } from './types'
import { genNodeMetaData } from '@/app/components/workflow/utils' import { genNodeMetaData } from '@/app/components/workflow/utils'
import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
import { CollectionType } from '@/app/components/tools/types'
import { OUTPUT_VARIABLES_MAP } from './constants'
const metaData = genNodeMetaData({ const metaData = genNodeMetaData({
sort: -1, sort: -1,
@ -9,13 +11,42 @@ const metaData = genNodeMetaData({
}) })
const nodeDefault: NodeDefault<DataSourceNodeType> = { const nodeDefault: NodeDefault<DataSourceNodeType> = {
metaData, metaData,
defaultValue: {}, defaultValue: {
datasource_parameters: {},
datasource_configurations: {},
},
checkValid() { checkValid() {
return { return {
isValid: true, isValid: true,
errorMessage: '', errorMessage: '',
} }
}, },
getOutputVars(payload) {
const { provider_id, provider_type } = payload
const isLocalFile = provider_id === 'langgenius/file/file' && provider_type === CollectionType.datasource
return [
{
variable: OUTPUT_VARIABLES_MAP.datasource_type.name,
type: OUTPUT_VARIABLES_MAP.datasource_type.type,
},
...(
isLocalFile
? [
{
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,
}
}),
},
]
: []
),
]
},
} }
export default nodeDefault export default nodeDefault

@ -8,6 +8,7 @@ import { BoxGroupField } from '@/app/components/workflow/nodes/_base/components/
import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
import TagInput from '@/app/components/base/tag-input' import TagInput from '@/app/components/base/tag-input'
import { useConfig } from './hooks/use-config' import { useConfig } from './hooks/use-config'
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()
@ -46,53 +47,17 @@ const Panel: FC<NodePanelProps<DataSourceNodeType>> = ({ id, data }) => {
} }
<OutputVars> <OutputVars>
<VarItem <VarItem
name='datasource_type' name={OUTPUT_VARIABLES_MAP.datasource_type.name}
type='string' type={OUTPUT_VARIABLES_MAP.datasource_type.type}
description={'local_file, online_document, website_crawl'} description={OUTPUT_VARIABLES_MAP.datasource_type.description}
/> />
{ {
isLocalFile && ( isLocalFile && (
<VarItem <VarItem
name='file' name={OUTPUT_VARIABLES_MAP.file.name}
type='Object' type={OUTPUT_VARIABLES_MAP.file.type}
description={'file'} description={OUTPUT_VARIABLES_MAP.file.description}
subItems={[ subItems={OUTPUT_VARIABLES_MAP.file.subItems}
{
name: 'type',
type: 'string',
description: '',
},
{
name: 'upload_file_id',
type: 'string',
description: '',
},
{
name: 'name',
type: 'string',
description: '',
},
{
name: 'size',
type: 'number',
description: '',
},
{
name: 'extension',
type: 'string',
description: '',
},
{
name: 'mime_type',
type: 'string',
description: '',
},
{
name: 'upload_file_url',
type: 'string',
description: '',
},
]}
/> />
) )
} }

@ -313,6 +313,7 @@ export type NodeDefault<T = {}> = {
} }
defaultValue: Partial<T> defaultValue: Partial<T>
checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string } checkValid: (payload: T, t: any, moreDataForCheckValid?: any) => { isValid: boolean; errorMessage?: string }
getOutputVars?: (payload: T) => Var[]
} }
export type OnSelectBlock = (type: BlockEnum, toolDefaultValue?: ToolDefaultValue | DataSourceDefaultValue) => void export type OnSelectBlock = (type: BlockEnum, toolDefaultValue?: ToolDefaultValue | DataSourceDefaultValue) => void

Loading…
Cancel
Save