feat(web): 增加模板节点
This commit is contained in:
@@ -6,9 +6,32 @@ import KnowledgeNode from './node/KnowledgeNode.tsx'
|
||||
import LlmNode from './node/LlmNode.tsx'
|
||||
import OutputNode from './node/OutputNode.tsx'
|
||||
import SwitchNode from './node/SwitchNode.tsx'
|
||||
import TemplateNode from './node/TemplateNode.tsx'
|
||||
import type {NodeChecker} from './types.ts'
|
||||
|
||||
const inputVariableChecker: NodeChecker = (id, inputSchema, nodes, edges, data) => {
|
||||
const inputSingleVariableChecker: (field: string) => NodeChecker = field => {
|
||||
return (id, inputSchema, nodes, edges, data) => {
|
||||
let nodeData = data[id] ?? {}
|
||||
if (has(nodeData, field)) {
|
||||
let expression = nodeData?.[field] ?? ''
|
||||
if (!isEmpty(expression)) {
|
||||
let outputVariables = new Set([
|
||||
...getAllIncomerNodeOutputVariables(id, nodes, edges, data).map(i => `${i.id}.${i.variable}`),
|
||||
...Object.keys(inputSchema),
|
||||
])
|
||||
if (!outputVariables.has(expression)) {
|
||||
return {
|
||||
error: true,
|
||||
message: `节点 ${id} 存在错误:变量 ${expression} 不存在`,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {error: false}
|
||||
}
|
||||
}
|
||||
|
||||
const inputMultiVariableChecker: NodeChecker = (id, inputSchema, nodes, edges, data) => {
|
||||
let nodeData = data[id] ?? {}
|
||||
if (has(nodeData, 'inputs')) {
|
||||
let inputs = nodeData?.inputs ?? {}
|
||||
@@ -49,7 +72,7 @@ export const NodeRegistry: NodeDefine[] = [
|
||||
icon: <i className="fa fa-message"/>,
|
||||
description: '使用大模型对话',
|
||||
component: LlmNode,
|
||||
checkers: [inputVariableChecker],
|
||||
checkers: [inputMultiVariableChecker],
|
||||
},
|
||||
{
|
||||
key: 'knowledge-node',
|
||||
@@ -58,7 +81,7 @@ export const NodeRegistry: NodeDefine[] = [
|
||||
icon: <i className="fa fa-book-bookmark"/>,
|
||||
description: '',
|
||||
component: KnowledgeNode,
|
||||
checkers: [inputVariableChecker],
|
||||
checkers: [inputMultiVariableChecker],
|
||||
},
|
||||
{
|
||||
key: 'code-node',
|
||||
@@ -67,7 +90,16 @@ export const NodeRegistry: NodeDefine[] = [
|
||||
icon: <i className="fa fa-code"/>,
|
||||
description: '执行自定义的处理代码',
|
||||
component: CodeNode,
|
||||
checkers: [inputVariableChecker],
|
||||
checkers: [inputMultiVariableChecker],
|
||||
},
|
||||
{
|
||||
key: 'template-node',
|
||||
group: '普通节点',
|
||||
name: '模板替换',
|
||||
icon: <i className="fa fa-pen-nib"/>,
|
||||
description: '使用模板聚合转换变量表示',
|
||||
component: TemplateNode,
|
||||
checkers: [inputMultiVariableChecker],
|
||||
},
|
||||
{
|
||||
key: 'switch-node',
|
||||
@@ -85,7 +117,7 @@ export const NodeRegistry: NodeDefine[] = [
|
||||
icon: <i className="fa fa-file"/>,
|
||||
description: '定义输出变量',
|
||||
component: OutputNode,
|
||||
checkers: [inputVariableChecker],
|
||||
checkers: [inputSingleVariableChecker('output')],
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user