From 7238ad80784882bbe76cb5cac7d5b51af7ad8dcc Mon Sep 17 00:00:00 2001 From: hejl Date: Mon, 28 Oct 2024 14:38:23 +0800 Subject: [PATCH 1/2] transform the files from dict to File when draft run single tool node --- api/core/workflow/workflow_entry.py | 19 +++++++++++++++++++ api/services/workflow_service.py | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/api/core/workflow/workflow_entry.py b/api/core/workflow/workflow_entry.py index eb812bad21..38fd9e3340 100644 --- a/api/core/workflow/workflow_entry.py +++ b/api/core/workflow/workflow_entry.py @@ -290,5 +290,24 @@ class WorkflowEntry: if new_value: input_value = new_value + if node_type == NodeType.TOOL and isinstance(input_value, dict) and "transferMethod" in input_value: + if input_value.get("supportFileType"): + type = FileType.value_of(input_value.get("supportFileType")) + else: + type = FileType.CUSTOM + transfer_method = FileTransferMethod.value_of(input_value.get("transferMethod")) + file = File( + tenant_id=tenant_id, + type=type, + transfer_method=transfer_method, + remote_url=input_value.get("url") + if transfer_method == FileTransferMethod.REMOTE_URL + else None, + related_id=input_value.get("uploadedId") + if transfer_method == FileTransferMethod.LOCAL_FILE + else None, + ) + input_value = file + # append variable and value to variable pool variable_pool.add([variable_node_id] + variable_key_list, input_value) diff --git a/api/services/workflow_service.py b/api/services/workflow_service.py index 7187d40517..3b64a6c21b 100644 --- a/api/services/workflow_service.py +++ b/api/services/workflow_service.py @@ -6,6 +6,7 @@ from typing import Optional from core.app.apps.advanced_chat.app_config_manager import AdvancedChatAppConfigManager from core.app.apps.workflow.app_config_manager import WorkflowAppConfigManager +from core.file.models import File from core.model_runtime.utils.encoders import jsonable_encoder from core.variables import Variable from core.workflow.entities.node_entities import NodeRunResult @@ -262,6 +263,9 @@ class WorkflowService: if run_succeeded and node_run_result: # create workflow node execution + for key, value in node_run_result.inputs.items(): + if isinstance(value, File): + node_run_result.inputs[key] = value.to_dict() workflow_node_execution.inputs = json.dumps(node_run_result.inputs) if node_run_result.inputs else None workflow_node_execution.process_data = ( json.dumps(node_run_result.process_data) if node_run_result.process_data else None From 925fc39e9414991c7230ec60b998737a00f34c26 Mon Sep 17 00:00:00 2001 From: hejl Date: Mon, 28 Oct 2024 14:53:51 +0800 Subject: [PATCH 2/2] fix CI --- api/core/workflow/workflow_entry.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/core/workflow/workflow_entry.py b/api/core/workflow/workflow_entry.py index 38fd9e3340..c71026bd3c 100644 --- a/api/core/workflow/workflow_entry.py +++ b/api/core/workflow/workflow_entry.py @@ -300,9 +300,7 @@ class WorkflowEntry: tenant_id=tenant_id, type=type, transfer_method=transfer_method, - remote_url=input_value.get("url") - if transfer_method == FileTransferMethod.REMOTE_URL - else None, + remote_url=input_value.get("url") if transfer_method == FileTransferMethod.REMOTE_URL else None, related_id=input_value.get("uploadedId") if transfer_method == FileTransferMethod.LOCAL_FILE else None,