diff --git a/api/core/app/apps/workflow/app_runner.py b/api/core/app/apps/workflow/app_runner.py index b43daa8a15..4d368136ca 100644 --- a/api/core/app/apps/workflow/app_runner.py +++ b/api/core/app/apps/workflow/app_runner.py @@ -82,7 +82,6 @@ class WorkflowAppRunner(WorkflowBasedAppRunner): workflow=workflow, node_id=self.application_generate_entity.single_iteration_run.node_id, user_inputs=self.application_generate_entity.single_iteration_run.inputs, - variable_loader=self._var_loader, ) elif self.application_generate_entity.single_loop_run: # if only single loop run is requested diff --git a/api/core/workflow/entities/node_entities.py b/api/core/workflow/entities/node_entities.py index 82fd6cdc30..df7d19cb75 100644 --- a/api/core/workflow/entities/node_entities.py +++ b/api/core/workflow/entities/node_entities.py @@ -1,4 +1,4 @@ -from collections.abc import Mapping +from collections.abc import Mapping, MutableMapping from enum import StrEnum from typing import Any, Optional @@ -43,7 +43,7 @@ class NodeRunResult(BaseModel): inputs: Optional[Mapping[str, Any]] = None # node inputs process_data: Optional[Mapping[str, Any]] = None # process data outputs: Optional[Mapping[str, Any]] = None # node outputs - metadata: Optional[Mapping[NodeRunMetadataKey, Any]] = None # node metadata + metadata: Optional[MutableMapping[NodeRunMetadataKey, Any]] = None # node metadata llm_usage: Optional[LLMUsage] = None # llm usage edge_source_handle: Optional[str] = None # source handle id of node with multiple branches diff --git a/api/core/workflow/nodes/llm/file_saver.py b/api/core/workflow/nodes/llm/file_saver.py index c85baade03..a4b45ce652 100644 --- a/api/core/workflow/nodes/llm/file_saver.py +++ b/api/core/workflow/nodes/llm/file_saver.py @@ -119,9 +119,6 @@ class FileSaverImpl(LLMFileSaver): size=len(data), related_id=tool_file.id, url=url, - # TODO(QuantumGhost): how should I set the following key? - # What's the difference between `remote_url` and `url`? - # What's the purpose of `storage_key` and `dify_model_identity`? storage_key=tool_file.file_key, ) diff --git a/api/core/workflow/nodes/loop/loop_node.py b/api/core/workflow/nodes/loop/loop_node.py index 088c003d3e..f6a12d60c1 100644 --- a/api/core/workflow/nodes/loop/loop_node.py +++ b/api/core/workflow/nodes/loop/loop_node.py @@ -478,7 +478,7 @@ class LoopNode(BaseNode[LoopNodeData]): variable_mapping.update(sub_node_variable_mapping) - for loop_variable in node_data.loop_variables: + for loop_variable in node_data.loop_variables or []: if loop_variable.value_type == "variable": assert loop_variable.value is not None, "Loop variable value must be provided for variable type" # add loop variable to variable mapping diff --git a/api/core/workflow/variable_loader.py b/api/core/workflow/variable_loader.py index 4e9bedb41e..4648a9b752 100644 --- a/api/core/workflow/variable_loader.py +++ b/api/core/workflow/variable_loader.py @@ -1,5 +1,5 @@ import abc -from collections.abc import Mapping +from collections.abc import Mapping, Sequence from typing import Any, Protocol from core.variables import Variable @@ -55,7 +55,7 @@ DUMMY_VARIABLE_LOADER = _DummyVariableLoader() def load_into_variable_pool( variable_loader: VariableLoader, variable_pool: VariablePool, - variable_mapping: Mapping[str, list[str]], + variable_mapping: Mapping[str, Sequence[str]], user_inputs: Mapping[str, Any], ): # Loading missing variable from draft var here, and set it into diff --git a/api/libs/gen_utils.py b/api/libs/gen_utils.py index e457176187..012c48b09f 100644 --- a/api/libs/gen_utils.py +++ b/api/libs/gen_utils.py @@ -1,31 +1,11 @@ """Utility functions for working with generators.""" -import logging from collections.abc import Callable, Generator -from inspect import isgenerator from typing import TypeVar _YieldT = TypeVar("_YieldT") _YieldR = TypeVar("_YieldR") -_T = TypeVar("_T") - - -def inspect(gen_or_normal: _T, logger: logging.Logger) -> _T: - if not isgenerator(gen_or_normal): - return gen_or_normal - - def wrapper(): - for item in gen_or_normal: - logger.info( - "received generator item, type=%s, value=%s", - type(item), - item, - ) - yield item - - return wrapper() - def map_( gen: Generator[_YieldT, None, None], diff --git a/api/services/workflow_service.py b/api/services/workflow_service.py index 8a71fcf3aa..87ba69c4dd 100644 --- a/api/services/workflow_service.py +++ b/api/services/workflow_service.py @@ -459,7 +459,6 @@ class WorkflowService: ) -> NodeExecution: try: node_instance, generator = invoke_node_fn() - generator = gen_utils.inspect(generator, logging.getLogger(__name__)) node_run_result: NodeRunResult | None = None for event in generator: