Bläddra i källkod

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

tags/0.10.1
-LAN- 1 år sedan
förälder
incheckning
2e657b7b12
Inget konto är kopplat till bidragsgivarens mejladress
1 ändrade filer med 11 tillägg och 9 borttagningar
  1. 11
    9
      api/core/workflow/nodes/llm/node.py

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

from core.prompt.advanced_prompt_transform import AdvancedPromptTransform from core.prompt.advanced_prompt_transform import AdvancedPromptTransform
from core.prompt.entities.advanced_prompt_entities import CompletionModelPromptTemplate, MemoryConfig from core.prompt.entities.advanced_prompt_entities import CompletionModelPromptTemplate, MemoryConfig
from core.prompt.utils.prompt_message_util import PromptMessageUtil 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.constants import SYSTEM_VARIABLE_NODE_ID
from core.workflow.entities.node_entities import NodeRunMetadataKey, NodeRunResult from core.workflow.entities.node_entities import NodeRunMetadataKey, NodeRunResult
from core.workflow.enums import SystemVariableKey from core.workflow.enums import SystemVariableKey
variable_selectors = variable_template_parser.extract_variable_selectors() variable_selectors = variable_template_parser.extract_variable_selectors()


for variable_selector in 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") 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 memory = node_data.memory
if memory and memory.query_prompt_template: if memory and memory.query_prompt_template:
template=memory.query_prompt_template template=memory.query_prompt_template
).extract_variable_selectors() ).extract_variable_selectors()
for variable_selector in query_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") 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 return inputs



Laddar…
Avbryt
Spara