From cfc408095cdfcd68c507deec7a32bffd5e6eecf0 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Tue, 23 Jul 2024 15:51:07 +0800 Subject: [PATCH] fix(api/nodes): Fallback to `get_any` in some nodes that use object or array. (#6566) --- api/core/workflow/nodes/code/code_node.py | 5 +++-- api/core/workflow/nodes/end/end_node.py | 4 ++-- .../workflow/nodes/http_request/http_executor.py | 8 ++++---- .../knowledge_retrieval/knowledge_retrieval_node.py | 4 ++-- .../parameter_extractor/parameter_extractor_node.py | 8 ++++---- .../variable_aggregator/variable_aggregator_node.py | 12 ++++++------ 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/api/core/workflow/nodes/code/code_node.py b/api/core/workflow/nodes/code/code_node.py index b2c362b983..fafd43e5bc 100644 --- a/api/core/workflow/nodes/code/code_node.py +++ b/api/core/workflow/nodes/code/code_node.py @@ -59,8 +59,9 @@ class CodeNode(BaseNode): variables = {} for variable_selector in node_data.variables: variable = variable_selector.variable - value = variable_pool.get(variable_selector.value_selector) - variables[variable] = value.value if value else None + value = variable_pool.get_any(variable_selector.value_selector) + + variables[variable] = value # Run code try: result = CodeExecutor.execute_workflow_code_template( diff --git a/api/core/workflow/nodes/end/end_node.py b/api/core/workflow/nodes/end/end_node.py index 17488f7253..440dfa2f27 100644 --- a/api/core/workflow/nodes/end/end_node.py +++ b/api/core/workflow/nodes/end/end_node.py @@ -24,8 +24,8 @@ class EndNode(BaseNode): outputs = {} for variable_selector in output_variables: - value = variable_pool.get(variable_selector.value_selector) - outputs[variable_selector.variable] = value.value if value else None + value = variable_pool.get_any(variable_selector.value_selector) + outputs[variable_selector.variable] = value return NodeRunResult( status=WorkflowNodeExecutionStatus.SUCCEEDED, diff --git a/api/core/workflow/nodes/http_request/http_executor.py b/api/core/workflow/nodes/http_request/http_executor.py index 473d85f073..3c24c0a018 100644 --- a/api/core/workflow/nodes/http_request/http_executor.py +++ b/api/core/workflow/nodes/http_request/http_executor.py @@ -333,13 +333,13 @@ class HttpExecutor: if variable_pool: variable_value_mapping = {} 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: raise ValueError(f'Variable {variable_selector.variable} not found') - if escape_quotes and isinstance(variable.value, str): - value = variable.value.replace('"', '\\"') + if escape_quotes and isinstance(variable, str): + value = variable.replace('"', '\\"') else: - value = variable.value + value = variable variable_value_mapping[variable_selector.variable] = value return variable_template_parser.format(variable_value_mapping), variable_selectors diff --git a/api/core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py b/api/core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py index 6e1534b3c2..ccd45d1383 100644 --- a/api/core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py +++ b/api/core/workflow/nodes/knowledge_retrieval/knowledge_retrieval_node.py @@ -41,8 +41,8 @@ class KnowledgeRetrievalNode(BaseNode): node_data: KnowledgeRetrievalNodeData = cast(self._node_data_cls, self.node_data) # extract variables - variable = variable_pool.get(node_data.query_variable_selector) - query = variable.value if variable else None + variable = variable_pool.get_any(node_data.query_variable_selector) + query = variable variables = { 'query': query } diff --git a/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py b/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py index 1fe6896e89..2876695a82 100644 --- a/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py +++ b/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py @@ -71,10 +71,10 @@ class ParameterExtractorNode(LLMNode): Run the node. """ 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: raise ValueError("Input variable content not found or is empty") - query = variable.value + query = variable inputs = { 'query': query, @@ -565,8 +565,8 @@ class ParameterExtractorNode(LLMNode): variable_template_parser = VariableTemplateParser(instruction) inputs = {} for selector in variable_template_parser.extract_variable_selectors(): - variable = variable_pool.get(selector.value_selector) - inputs[selector.variable] = variable.value if variable else None + variable = variable_pool.get_any(selector.value_selector) + inputs[selector.variable] = variable return variable_template_parser.format(inputs) diff --git a/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py b/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py index 1e49476066..885f7d7617 100644 --- a/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py +++ b/api/core/workflow/nodes/variable_aggregator/variable_aggregator_node.py @@ -20,26 +20,26 @@ class VariableAggregatorNode(BaseNode): if not node_data.advanced_settings or not node_data.advanced_settings.group_enabled: for selector in node_data.variables: - variable = variable_pool.get(selector) + variable = variable_pool.get_any(selector) if variable is not None: outputs = { - "output": variable.value + "output": variable } inputs = { - '.'.join(selector[1:]): variable.value + '.'.join(selector[1:]): variable } break else: for group in node_data.advanced_settings.groups: for selector in group.variables: - variable = variable_pool.get(selector) + variable = variable_pool.get_any(selector) if variable is not None: outputs[group.group_name] = { - 'output': variable.value + 'output': variable } - inputs['.'.join(selector[1:])] = variable.value + inputs['.'.join(selector[1:])] = variable break return NodeRunResult(