Skip to content

Commit

Permalink
fix(api/nodes): Fallback to get_any in some nodes that use object o…
Browse files Browse the repository at this point in the history
…r array. (langgenius#6566)
  • Loading branch information
laipz8200 authored and cuiks committed Aug 6, 2024
1 parent a8317fd commit 3b1d3c1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
5 changes: 3 additions & 2 deletions api/core/workflow/nodes/code/code_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:
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(
Expand Down
4 changes: 2 additions & 2 deletions api/core/workflow/nodes/end/end_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:

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,
Expand Down
8 changes: 4 additions & 4 deletions api/core/workflow/nodes/http_request/http_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ def _format_template(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:
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,
Expand Down Expand Up @@ -565,8 +565,8 @@ def _render_instruction(self, instruction: str, variable_pool: VariablePool) ->
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:

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(
Expand Down

0 comments on commit 3b1d3c1

Please sign in to comment.