mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat: Add structured output to sub-graph LLM nodes
This commit is contained in:
@ -16,6 +16,7 @@ import { useStoreApi } from 'reactflow'
|
||||
import PromptEditor from '@/app/components/base/prompt-editor'
|
||||
import { useNodesMetaData, useNodesSyncDraft } from '@/app/components/workflow/hooks'
|
||||
import { VarKindType as VarKindTypeEnum } from '@/app/components/workflow/nodes/_base/types'
|
||||
import { Type } from '@/app/components/workflow/nodes/llm/types'
|
||||
import { useStore } from '@/app/components/workflow/store'
|
||||
import { BlockEnum } from '@/app/components/workflow/types'
|
||||
import { generateNewNode, getNodeCustomTypeByNodeDataType } from '@/app/components/workflow/utils'
|
||||
@ -163,6 +164,19 @@ const MixedVariableTextInput = ({
|
||||
title: defaultValue.title,
|
||||
desc: defaultValue.desc || '',
|
||||
parent_node_id: toolNodeId,
|
||||
structured_output_enabled: true,
|
||||
structured_output: {
|
||||
schema: {
|
||||
type: Type.object,
|
||||
properties: {
|
||||
[paramKey]: {
|
||||
type: Type.string,
|
||||
},
|
||||
},
|
||||
required: [paramKey],
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
position: {
|
||||
x: 0,
|
||||
@ -175,7 +189,12 @@ const MixedVariableTextInput = ({
|
||||
}
|
||||
}
|
||||
|
||||
onChange(newValue, VarKindTypeEnum.mention, DEFAULT_MENTION_CONFIG)
|
||||
const mentionConfigWithOutputSelector: MentionConfig = {
|
||||
...DEFAULT_MENTION_CONFIG,
|
||||
extractor_node_id: toolNodeId && paramKey ? `${toolNodeId}_ext_${paramKey}` : '',
|
||||
output_selector: paramKey ? ['structured_output', paramKey] : [],
|
||||
}
|
||||
onChange(newValue, VarKindTypeEnum.mention, mentionConfigWithOutputSelector)
|
||||
setControlPromptEditorRerenderKey(Date.now())
|
||||
}, [handleSyncWorkflowDraft, nodesMetaDataMap, onChange, paramKey, reactFlowStore, setControlPromptEditorRerenderKey, toolNodeId, value])
|
||||
|
||||
|
||||
@ -47,13 +47,15 @@ const SubGraphModal: FC<SubGraphModalProps> = ({
|
||||
const current = toolParam?.mention_config
|
||||
const rawSelector = Array.isArray(current?.output_selector) ? current!.output_selector : []
|
||||
const outputSelector = rawSelector[0] === extractorNodeId ? rawSelector.slice(1) : rawSelector
|
||||
const defaultOutputSelector = ['structured_output', paramKey]
|
||||
|
||||
return {
|
||||
extractor_node_id: current?.extractor_node_id || extractorNodeId,
|
||||
output_selector: outputSelector,
|
||||
output_selector: outputSelector.length > 0 ? outputSelector : defaultOutputSelector,
|
||||
null_strategy: current?.null_strategy || 'use_default',
|
||||
default_value: current?.default_value ?? '',
|
||||
}
|
||||
}, [extractorNodeId, toolParam?.mention_config])
|
||||
}, [extractorNodeId, paramKey, toolParam?.mention_config])
|
||||
|
||||
const handleMentionConfigChange = useCallback((config: MentionConfig) => {
|
||||
const { getNodes, setNodes } = reactflowStore.getState()
|
||||
|
||||
Reference in New Issue
Block a user