mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 21:28:25 +08:00
Infer human input output variable types
This commit is contained in:
parent
63711bf1dc
commit
acd1641d16
@ -503,8 +503,10 @@ describe('DSL Import with Human Input Node', () => {
|
||||
const payload = {
|
||||
...humanInputDefault.defaultValue,
|
||||
inputs: [
|
||||
{ type: 'text-input', output_variable_name: 'review_result', default: { selector: [], type: 'constant' as const, value: '' } },
|
||||
{ type: 'text-input', output_variable_name: 'comment', default: { selector: [], type: 'constant' as const, value: '' } },
|
||||
{ type: 'paragraph', output_variable_name: 'review_result', default: { selector: [], type: 'constant' as const, value: '' } },
|
||||
{ type: 'file', output_variable_name: 'attachment', allowed_file_extensions: [], allowed_file_types: [], allowed_file_upload_methods: [] },
|
||||
{ type: 'file-list', output_variable_name: 'attachments', allowed_file_extensions: [], allowed_file_types: [], allowed_file_upload_methods: [], max_upload_count: 3 },
|
||||
{ type: 'select', output_variable_name: 'comment', option_source: { type: 'constant', selector: [], value: ['A', 'B'] } },
|
||||
],
|
||||
} as HumanInputNodeType
|
||||
|
||||
@ -512,6 +514,8 @@ describe('DSL Import with Human Input Node', () => {
|
||||
|
||||
expect(outputVars).toEqual([
|
||||
{ variable: 'review_result', type: 'string' },
|
||||
{ variable: 'attachment', type: 'file' },
|
||||
{ variable: 'attachments', type: 'array[file]' },
|
||||
{ variable: 'comment', type: 'string' },
|
||||
])
|
||||
})
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import type { NodeDefault, Var } from '../../types'
|
||||
import type { HumanInputNodeType } from './types'
|
||||
import type { FormInputItem, HumanInputNodeType } from './types'
|
||||
import { BlockClassificationEnum } from '@/app/components/workflow/block-selector/types'
|
||||
import { BlockEnum, VarType } from '@/app/components/workflow/types'
|
||||
import { genNodeMetaData } from '@/app/components/workflow/utils'
|
||||
@ -12,11 +12,21 @@ const metaData = genNodeMetaData({
|
||||
type: BlockEnum.HumanInput,
|
||||
})
|
||||
|
||||
const buildOutputVars = (variables: string[]): Var[] => {
|
||||
return variables.map((variable) => {
|
||||
const getFormInputVarType = (input: FormInputItem): VarType => {
|
||||
if (input.type === 'file')
|
||||
return VarType.file
|
||||
|
||||
if (input.type === 'file-list')
|
||||
return VarType.arrayFile
|
||||
|
||||
return VarType.string
|
||||
}
|
||||
|
||||
const buildOutputVars = (inputs: FormInputItem[]): Var[] => {
|
||||
return inputs.map((input) => {
|
||||
return {
|
||||
variable,
|
||||
type: VarType.string,
|
||||
variable: input.output_variable_name,
|
||||
type: getFormInputVarType(input),
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -67,8 +77,7 @@ const nodeDefault: NodeDefault<HumanInputNodeType> = {
|
||||
}
|
||||
},
|
||||
getOutputVars(payload, _allPluginInfoList, _ragVars) {
|
||||
const variables = payload.inputs.map(input => input.output_variable_name)
|
||||
return buildOutputVars(variables)
|
||||
return buildOutputVars(payload.inputs)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user