fix(api/nodes): Fallback to get_any in some nodes that use object or array. (#6566)

This commit is contained in:
-LAN- 2024-07-23 15:51:07 +08:00 committed by GitHub
parent 6b5fac3004
commit cfc408095c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 20 deletions

View File

@ -59,8 +59,9 @@ class CodeNode(BaseNode):
variables = {} variables = {}
for variable_selector in node_data.variables: for variable_selector in node_data.variables:
variable = variable_selector.variable variable = variable_selector.variable
value = variable_pool.get(variable_selector.value_selector) value = variable_pool.get_any(variable_selector.value_selector)
variables[variable] = value.value if value else None
variables[variable] = value
# Run code # Run code
try: try:
result = CodeExecutor.execute_workflow_code_template( result = CodeExecutor.execute_workflow_code_template(

View File

@ -24,8 +24,8 @@ class EndNode(BaseNode):
outputs = {} outputs = {}
for variable_selector in output_variables: for variable_selector in output_variables:
value = variable_pool.get(variable_selector.value_selector) value = variable_pool.get_any(variable_selector.value_selector)
outputs[variable_selector.variable] = value.value if value else None outputs[variable_selector.variable] = value
return NodeRunResult( return NodeRunResult(
status=WorkflowNodeExecutionStatus.SUCCEEDED, status=WorkflowNodeExecutionStatus.SUCCEEDED,

View File

@ -333,13 +333,13 @@ class HttpExecutor:
if variable_pool: if variable_pool:
variable_value_mapping = {} variable_value_mapping = {}
for variable_selector in variable_selectors: for variable_selector in variable_selectors:
variable = variable_pool.get(variable_selector.value_selector) variable = variable_pool.get_any(variable_selector.value_selector)
if variable is None: if variable is None:
raise ValueError(f'Variable {variable_selector.variable} not found') raise ValueError(f'Variable {variable_selector.variable} not found')
if escape_quotes and isinstance(variable.value, str): if escape_quotes and isinstance(variable, str):
value = variable.value.replace('"', '\\"') value = variable.replace('"', '\\"')
else: else:
value = variable.value value = variable
variable_value_mapping[variable_selector.variable] = value variable_value_mapping[variable_selector.variable] = value
return variable_template_parser.format(variable_value_mapping), variable_selectors return variable_template_parser.format(variable_value_mapping), variable_selectors

View File

@ -41,8 +41,8 @@ class KnowledgeRetrievalNode(BaseNode):
node_data: KnowledgeRetrievalNodeData = cast(self._node_data_cls, self.node_data) node_data: KnowledgeRetrievalNodeData = cast(self._node_data_cls, self.node_data)
# extract variables # extract variables
variable = variable_pool.get(node_data.query_variable_selector) variable = variable_pool.get_any(node_data.query_variable_selector)
query = variable.value if variable else None query = variable
variables = { variables = {
'query': query 'query': query
} }

View File

@ -71,10 +71,10 @@ class ParameterExtractorNode(LLMNode):
Run the node. Run the node.
""" """
node_data = cast(ParameterExtractorNodeData, self.node_data) node_data = cast(ParameterExtractorNodeData, self.node_data)
variable = variable_pool.get(node_data.query) variable = variable_pool.get_any(node_data.query)
if not variable: if not variable:
raise ValueError("Input variable content not found or is empty") raise ValueError("Input variable content not found or is empty")
query = variable.value query = variable
inputs = { inputs = {
'query': query, 'query': query,
@ -565,8 +565,8 @@ class ParameterExtractorNode(LLMNode):
variable_template_parser = VariableTemplateParser(instruction) variable_template_parser = VariableTemplateParser(instruction)
inputs = {} inputs = {}
for selector in variable_template_parser.extract_variable_selectors(): for selector in variable_template_parser.extract_variable_selectors():
variable = variable_pool.get(selector.value_selector) variable = variable_pool.get_any(selector.value_selector)
inputs[selector.variable] = variable.value if variable else None inputs[selector.variable] = variable
return variable_template_parser.format(inputs) return variable_template_parser.format(inputs)

View File

@ -20,26 +20,26 @@ class VariableAggregatorNode(BaseNode):
if not node_data.advanced_settings or not node_data.advanced_settings.group_enabled: if not node_data.advanced_settings or not node_data.advanced_settings.group_enabled:
for selector in node_data.variables: for selector in node_data.variables:
variable = variable_pool.get(selector) variable = variable_pool.get_any(selector)
if variable is not None: if variable is not None:
outputs = { outputs = {
"output": variable.value "output": variable
} }
inputs = { inputs = {
'.'.join(selector[1:]): variable.value '.'.join(selector[1:]): variable
} }
break break
else: else:
for group in node_data.advanced_settings.groups: for group in node_data.advanced_settings.groups:
for selector in group.variables: for selector in group.variables:
variable = variable_pool.get(selector) variable = variable_pool.get_any(selector)
if variable is not None: if variable is not None:
outputs[group.group_name] = { outputs[group.group_name] = {
'output': variable.value 'output': variable
} }
inputs['.'.join(selector[1:])] = variable.value inputs['.'.join(selector[1:])] = variable
break break
return NodeRunResult( return NodeRunResult(