Selaa lähdekoodia

fix(workflow): handle NoneSegments in variable extraction (#9585)

-LAN- 6 kuukautta sitten
vanhempi
commit
2e657b7b12
1 muutettua tiedostoa jossa 11 lisäystä ja 9 poistoa
  1. 11 9
      api/core/workflow/nodes/llm/node.py

+ 11 - 9
api/core/workflow/nodes/llm/node.py

@@ -22,7 +22,7 @@ from core.model_runtime.utils.encoders import jsonable_encoder
 from core.prompt.advanced_prompt_transform import AdvancedPromptTransform
 from core.prompt.entities.advanced_prompt_entities import CompletionModelPromptTemplate, MemoryConfig
 from core.prompt.utils.prompt_message_util import PromptMessageUtil
-from core.variables import ArrayAnySegment, ArrayFileSegment, FileSegment
+from core.variables import ArrayAnySegment, ArrayFileSegment, FileSegment, NoneSegment
 from core.workflow.constants import SYSTEM_VARIABLE_NODE_ID
 from core.workflow.entities.node_entities import NodeRunMetadataKey, NodeRunResult
 from core.workflow.enums import SystemVariableKey
@@ -320,11 +320,12 @@ class LLMNode(BaseNode[LLMNodeData]):
             variable_selectors = variable_template_parser.extract_variable_selectors()
 
         for variable_selector in variable_selectors:
-            variable_value = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
-            if variable_value is None:
+            variable = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
+            if variable is None:
                 raise ValueError(f"Variable {variable_selector.variable} not found")
-
-            inputs[variable_selector.variable] = variable_value.to_object()
+            if isinstance(variable, NoneSegment):
+                continue
+            inputs[variable_selector.variable] = variable.to_object()
 
         memory = node_data.memory
         if memory and memory.query_prompt_template:
@@ -332,11 +333,12 @@ class LLMNode(BaseNode[LLMNodeData]):
                 template=memory.query_prompt_template
             ).extract_variable_selectors()
             for variable_selector in query_variable_selectors:
-                variable_value = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
-                if variable_value is None:
+                variable = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
+                if variable is None:
                     raise ValueError(f"Variable {variable_selector.variable} not found")
-
-                inputs[variable_selector.variable] = variable_value.to_object()
+                if isinstance(variable, NoneSegment):
+                    continue
+                inputs[variable_selector.variable] = variable.to_object()
 
         return inputs