From a8927a055ef733ca4f18d326c0225b1b77b348c7 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Thu, 27 Jun 2024 16:46:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=97=A0=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/application/flow/default_workflow.json | 8 ++++++ apps/application/flow/workflow_manage.py | 7 ++++- ui/src/workflow/common/NodeCascader.vue | 32 +++++++++------------ ui/src/workflow/common/data.ts | 10 ++++++- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/apps/application/flow/default_workflow.json b/apps/application/flow/default_workflow.json index 890f91f34..111d96502 100644 --- a/apps/application/flow/default_workflow.json +++ b/apps/application/flow/default_workflow.json @@ -29,6 +29,14 @@ "globeValue": "{{context['start-node'].question}}" } ], + "globalFields": [ + { + "value": "time", + "label": "当前时间", + "globeLabel": "{{全局变量.time}}", + "globeValue": "{{context['global'].time}}" + } + ], "height": 200, "stepName": "开始" } diff --git a/apps/application/flow/workflow_manage.py b/apps/application/flow/workflow_manage.py index bc59521ae..403f3a552 100644 --- a/apps/application/flow/workflow_manage.py +++ b/apps/application/flow/workflow_manage.py @@ -234,10 +234,15 @@ class WorkflowManage: } for node in self.node_context: - fields = node.node.properties.get('fields') + properties = node.node.properties + fields = properties.get('fields') if fields is not None: for field in fields: prompt = prompt.replace(field.get('globeLabel'), field.get('globeValue')) + global_fields = properties.get('globalFields') + if global_fields is not None: + for field in global_fields: + prompt = prompt.replace(field.get('globeLabel'), field.get('globeValue')) context[node.id] = node.context prompt_template = PromptTemplate.from_template(prompt, template_format='jinja2') diff --git a/ui/src/workflow/common/NodeCascader.vue b/ui/src/workflow/common/NodeCascader.vue index edbd6357e..b546d3eb5 100644 --- a/ui/src/workflow/common/NodeCascader.vue +++ b/ui/src/workflow/common/NodeCascader.vue @@ -28,14 +28,7 @@ const options = ref>([ value: 'global', label: '全局变量', type: 'global', - children: [ - { - value: 'time', - label: '当前时间', - globeLabel: '{{全局变量.time}}', - globeValue: "{{content['global'].time}}" - } - ] + children: [] } ]) @@ -46,14 +39,7 @@ function visibleChange(bool: boolean) { value: 'global', label: '全局变量', type: 'global', - children: [ - { - value: 'time', - label: '当前时间', - globeLabel: '{{全局变量.time}}', - globeValue: "{{content['global'].time}}" - } - ] + children: [] } ] getIncomingNode(props.nodeModel.id) @@ -62,7 +48,7 @@ function visibleChange(bool: boolean) { function getIncomingNode(id: string) { const list = props.nodeModel.graphModel.getNodeIncomingNode(id) - const firstElement = options.value.shift() + let firstElement = null if (list.length > 0) { list.forEach((item: any) => { if (!options.value.some((obj: any) => obj.id === item.id)) { @@ -72,6 +58,14 @@ function getIncomingNode(id: string) { type: item.type, children: item.properties?.fields || [] }) + if (item.properties?.globalFields && item.type === 'start-node') { + firstElement = { + value: 'global', + label: '全局变量', + type: 'global', + children: item.properties?.globalFields || [] + } + } } }) @@ -79,7 +73,9 @@ function getIncomingNode(id: string) { getIncomingNode(item.id) }) } - options.value.unshift(firstElement) + if (firstElement) { + options.value.unshift(firstElement) + } } onMounted(() => { getIncomingNode(props.nodeModel.id) diff --git a/ui/src/workflow/common/data.ts b/ui/src/workflow/common/data.ts index e56f823d4..825aa51d5 100644 --- a/ui/src/workflow/common/data.ts +++ b/ui/src/workflow/common/data.ts @@ -34,7 +34,15 @@ export const baseNodes = [ label: '用户问题', value: 'question', globeLabel: '{{开始.question}}', - globeValue: `{{content['${WorkflowType.Start}'].question}}` + globeValue: `{{context['${WorkflowType.Start}'].question}}` + } + ], + globalFields: [ + { + value: 'time', + label: '当前时间', + globeLabel: '{{全局变量.time}}', + globeValue: "{{context['global'].time}}" } ] }