99import time
1010from typing import Dict , List
1111
12+ from django .utils .translation import gettext as _
13+
1214from application .flow .common import Answer
1315from application .flow .i_step_node import NodeResult , WorkFlowPostHandler , INode
1416from application .flow .step_node .loop_node .i_loop_node import ILoopNode
1517from application .flow .tools import Reasoning
1618from application .models import ChatRecord
1719from common .handle .impl .response .loop_to_response import LoopToResponse
1820from maxkb .const import CONFIG
19- from django .utils .translation import gettext as _
2021
2122max_loop_count = int (CONFIG .get ("WORKFLOW_LOOP_NODE_MAX_LOOP_COUNT" , 500 ))
2223
@@ -173,7 +174,17 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
173174 answer += content_chunk
174175 yield chunk
175176 if chunk .get ('node_status' , "SUCCESS" ) == 'ERROR' :
176- raise Exception (chunk .get ('content' ))
177+ insert_or_replace (loop_node_data , index , instance .get_runtime_details ())
178+ insert_or_replace (loop_answer_data , index ,
179+ get_answer_list (instance , child_node_node_dict , node .runtime_node_id ))
180+ node .context ['is_interrupt_exec' ] = is_interrupt_exec
181+ node .context ['loop_node_data' ] = loop_node_data
182+ node .context ['loop_answer_data' ] = loop_answer_data
183+ node .context ["index" ] = current_index
184+ node .context ["item" ] = current_index
185+ node .status = 500
186+ node .err_message = chunk .get ('content' )
187+ return
177188 node_type = chunk .get ('node_type' )
178189 if node_type == 'form-node' :
179190 break_outer = True
@@ -182,7 +193,6 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
182193 start_node_data = None
183194 chat_record = None
184195 child_node = None
185- loop_global_data = instance .context
186196 insert_or_replace (loop_node_data , index , instance .get_runtime_details ())
187197 insert_or_replace (loop_answer_data , index ,
188198 get_answer_list (instance , child_node_node_dict , node .runtime_node_id ))
0 commit comments