improve block output jinja reference (#2006)

This commit is contained in:
Shuchang Zheng 2025-03-23 18:20:20 -07:00 committed by GitHub
parent 70adf8b9c6
commit 008cc26a15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 1 deletions

View file

@ -1,3 +1,4 @@
import copy
import uuid
from typing import TYPE_CHECKING, Any, Self
@ -584,8 +585,34 @@ class WorkflowRunContext:
LOG.warning(f"Output parameter {parameter.output_parameter_id} already has a registered value, overwriting")
self.values[parameter.key] = value
self.register_block_reference_variable_from_output_parameter(parameter, value)
await self.set_parameter_values_for_output_parameter_dependent_blocks(parameter, value)
def register_block_reference_variable_from_output_parameter(
self,
parameter: OutputParameter,
value: dict[str, Any] | list | str | None,
) -> None:
# output parameter key is formatted as `<block_label>_output`
if not parameter.key.endswith("_output"):
return
block_label = parameter.key.removesuffix("_output")
block_reference_value = copy.deepcopy(value)
if isinstance(block_reference_value, dict) and "extracted_information" in block_reference_value:
block_reference_value.update({"output": block_reference_value.get("extracted_information")})
if block_label in self.values:
current_value = self.values[block_label]
# only able to merge the value when the current value and the pending value are both dicts
if isinstance(current_value, dict) and isinstance(block_reference_value, dict):
block_reference_value.update(current_value)
else:
LOG.warning(f"Parameter {block_label} already has a value in workflow run context, overwriting")
self.values[block_label] = block_reference_value
async def set_parameter_values_for_output_parameter_dependent_blocks(
self,
output_parameter: OutputParameter,