fix: 修复全局变量无法错误

This commit is contained in:
shaohuzhang1 2024-06-27 16:46:15 +08:00
parent e795ab4baa
commit a8927a055e
4 changed files with 37 additions and 20 deletions

View File

@ -29,6 +29,14 @@
"globeValue": "{{context['start-node'].question}}"
}
],
"globalFields": [
{
"value": "time",
"label": "当前时间",
"globeLabel": "{{全局变量.time}}",
"globeValue": "{{context['global'].time}}"
}
],
"height": 200,
"stepName": "开始"
}

View File

@ -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')

View File

@ -28,14 +28,7 @@ const options = ref<Array<any>>([
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)

View File

@ -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}}"
}
]
}