Skip to content

Commit 74edbd0

Browse files
authored
feat: The workflow node cannot obtain values from other nodes, which is set as the default value (#1923)
1 parent 2529011 commit 74edbd0

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

apps/application/flow/workflow_manage.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,33 +693,43 @@ def get_reference_field(self, node_id: str, fields: List[str]):
693693
else:
694694
return self.get_node_by_id(node_id).get_reference_field(fields)
695695

696-
def generate_prompt(self, prompt: str):
697-
"""
698-
格式化生成提示词
699-
@param prompt: 提示词信息
700-
@return: 格式化后的提示词
701-
"""
696+
def get_workflow_content(self):
702697
context = {
703698
'global': self.context,
704699
}
705700

706701
for node in self.node_context:
707-
properties = node.node.properties
702+
context[node.id] = node.context
703+
return context
704+
705+
def reset_prompt(self, prompt: str):
706+
placeholder = "{}"
707+
for node in self.flow.nodes:
708+
properties = node.properties
708709
node_config = properties.get('config')
709710
if node_config is not None:
710711
fields = node_config.get('fields')
711712
if fields is not None:
712713
for field in fields:
713714
globeLabel = f"{properties.get('stepName')}.{field.get('value')}"
714-
globeValue = f"context['{node.id}'].{field.get('value')}"
715+
globeValue = f"context.get('{node.id}',{placeholder}).get('{field.get('value', '')}','')"
715716
prompt = prompt.replace(globeLabel, globeValue)
716717
global_fields = node_config.get('globalFields')
717718
if global_fields is not None:
718719
for field in global_fields:
719720
globeLabel = f"全局变量.{field.get('value')}"
720-
globeValue = f"context['global'].{field.get('value')}"
721+
globeValue = f"context.get('global').get('{field.get('value', '')}','')"
721722
prompt = prompt.replace(globeLabel, globeValue)
722-
context[node.id] = node.context
723+
return prompt
724+
725+
def generate_prompt(self, prompt: str):
726+
"""
727+
格式化生成提示词
728+
@param prompt: 提示词信息
729+
@return: 格式化后的提示词
730+
"""
731+
context = self.get_workflow_content()
732+
prompt = self.reset_prompt(prompt)
723733
prompt_template = PromptTemplate.from_template(prompt, template_format='jinja2')
724734
value = prompt_template.format(context=context)
725735
return value

0 commit comments

Comments
 (0)