From 00591a5b2552c8f7963090ab2317fedeb91c681d Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:04:25 +0800 Subject: [PATCH] fix: Workflow The condition setting 'any' did not take effect when the discriminator was executed (#1979) --- apps/application/flow/workflow_manage.py | 22 +++++++++++++++++----- ui/src/api/type/application.ts | 16 +++++++--------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/application/flow/workflow_manage.py b/apps/application/flow/workflow_manage.py index 9eab397f907..9cf5a625a29 100644 --- a/apps/application/flow/workflow_manage.py +++ b/apps/application/flow/workflow_manage.py @@ -10,6 +10,7 @@ import json import threading import traceback +import uuid from concurrent.futures import ThreadPoolExecutor from functools import reduce from typing import List, Dict @@ -575,7 +576,7 @@ def get_runtime_details(self): details['node_id'] = node.id details['up_node_id_list'] = node.up_node_id_list details['runtime_node_id'] = node.runtime_node_id - details_result[node.runtime_node_id] = details + details_result[str(uuid.uuid1())] = details return details_result def get_answer_text_list(self): @@ -664,9 +665,18 @@ def get_next_node_list(self, current_node, current_node_result): for edge in self.flow.edges: if (edge.sourceNodeId == current_node.id and f"{edge.sourceNodeId}_{current_node_result.node_variable.get('branch_id')}_right" == edge.sourceAnchorId): - if self.dependent_node_been_executed(edge.targetNodeId): + next_node = [node for node in self.flow.nodes if node.id == edge.targetNodeId] + if len(next_node) == 0: + continue + if next_node[0].properties.get('condition', "AND") == 'AND': + if self.dependent_node_been_executed(edge.targetNodeId): + node_list.append( + self.get_node_cls_by_id(edge.targetNodeId, + [*current_node.up_node_id_list, current_node.node.id])) + else: node_list.append( - self.get_node_cls_by_id(edge.targetNodeId, self.get_up_node_id_list(edge.targetNodeId))) + self.get_node_cls_by_id(edge.targetNodeId, + [*current_node.up_node_id_list, current_node.node.id])) else: for edge in self.flow.edges: if edge.sourceNodeId == current_node.id: @@ -676,10 +686,12 @@ def get_next_node_list(self, current_node, current_node_result): if next_node[0].properties.get('condition', "AND") == 'AND': if self.dependent_node_been_executed(edge.targetNodeId): node_list.append( - self.get_node_cls_by_id(edge.targetNodeId, self.get_up_node_id_list(edge.targetNodeId))) + self.get_node_cls_by_id(edge.targetNodeId, + [*current_node.up_node_id_list, current_node.node.id])) else: node_list.append( - self.get_node_cls_by_id(edge.targetNodeId, [current_node.node.id])) + self.get_node_cls_by_id(edge.targetNodeId, + [*current_node.up_node_id_list, current_node.node.id])) return node_list def get_reference_field(self, node_id: str, fields: List[str]): diff --git a/ui/src/api/type/application.ts b/ui/src/api/type/application.ts index 51dac2fedd0..404f5a55e8b 100644 --- a/ui/src/api/type/application.ts +++ b/ui/src/api/type/application.ts @@ -123,12 +123,11 @@ export class ChatRecordManage { this.chat.answer_text = this.chat.answer_text + chunk_answer } - get_current_up_node() { - for (let i = this.node_list.length - 2; i >= 0; i--) { - const n = this.node_list[i] - if (n.content.length > 0) { - return n - } + get_current_up_node(run_node: any) { + const index = this.node_list.findIndex((item) => item == run_node) + if (index > 0) { + const n = this.node_list[index - 1] + return n } return undefined } @@ -146,14 +145,13 @@ export class ChatRecordManage { const index = this.node_list.indexOf(run_node) let current_up_node = undefined if (index > 0) { - current_up_node = this.get_current_up_node() + current_up_node = this.get_current_up_node(run_node) } let answer_text_list_index = 0 - if ( current_up_node == undefined || run_node.view_type == 'single_view' || - (run_node.view_type == 'many_view' && current_up_node.view_type == 'single_view') + current_up_node.view_type == 'single_view' ) { const none_index = this.findIndex( this.chat.answer_text_list,