Ver Fonte

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

-LAN- há 9 meses atrás
pai
commit
cfc408095c

+ 3 - 2
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(

+ 2 - 2
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,

+ 4 - 4
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

+ 2 - 2
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
         }

+ 4 - 4
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)
 

+ 6 - 6
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(