@@ -19,7 +19,8 @@ def _is_interrupt_exec(node, node_variable: Dict, workflow_variable: Dict):
1919 return node_variable .get ('is_interrupt_exec' , False )
2020
2121
22- def _write_context (node_variable : Dict , workflow_variable : Dict , node : INode , workflow , answer : str ):
22+ def _write_context (node_variable : Dict , workflow_variable : Dict , node : INode , workflow , answer : str ,
23+ reasoning_content : str ):
2324 result = node_variable .get ('result' )
2425 node .context ['application_node_dict' ] = node_variable .get ('application_node_dict' )
2526 node .context ['node_dict' ] = node_variable .get ('node_dict' , {})
@@ -28,6 +29,7 @@ def _write_context(node_variable: Dict, workflow_variable: Dict, node: INode, wo
2829 node .context ['answer_tokens' ] = result .get ('usage' , {}).get ('completion_tokens' , 0 )
2930 node .context ['answer' ] = answer
3031 node .context ['result' ] = answer
32+ node .context ['reasoning_content' ] = reasoning_content
3133 node .context ['question' ] = node_variable ['question' ]
3234 node .context ['run_time' ] = time .time () - node .context ['start_time' ]
3335 if workflow .is_result (node , NodeResult (node_variable , workflow_variable )):
@@ -44,6 +46,7 @@ def write_context_stream(node_variable: Dict, workflow_variable: Dict, node: INo
4446 """
4547 response = node_variable .get ('result' )
4648 answer = ''
49+ reasoning_content = ''
4750 usage = {}
4851 node_child_node = {}
4952 application_node_dict = node .context .get ('application_node_dict' , {})
@@ -60,9 +63,11 @@ def write_context_stream(node_variable: Dict, workflow_variable: Dict, node: INo
6063 node_type = response_content .get ('node_type' )
6164 real_node_id = response_content .get ('real_node_id' )
6265 node_is_end = response_content .get ('node_is_end' , False )
66+ _reasoning_content = response_content .get ('reasoning_content' , '' )
6367 if node_type == 'form-node' :
6468 is_interrupt_exec = True
6569 answer += content
70+ reasoning_content += _reasoning_content
6671 node_child_node = {'runtime_node_id' : runtime_node_id , 'chat_record_id' : chat_record_id ,
6772 'child_node' : child_node }
6873
@@ -75,13 +80,16 @@ def write_context_stream(node_variable: Dict, workflow_variable: Dict, node: INo
7580 'chat_record_id' : chat_record_id ,
7681 'child_node' : child_node ,
7782 'index' : len (application_node_dict ),
78- 'view_type' : view_type }
83+ 'view_type' : view_type ,
84+ 'reasoning_content' : _reasoning_content }
7985 else :
8086 application_node ['content' ] += content
87+ application_node ['reasoning_content' ] += _reasoning_content
8188
8289 yield {'content' : content ,
8390 'node_type' : node_type ,
8491 'runtime_node_id' : runtime_node_id , 'chat_record_id' : chat_record_id ,
92+ 'reasoning_content' : _reasoning_content ,
8593 'child_node' : child_node ,
8694 'real_node_id' : real_node_id ,
8795 'node_is_end' : node_is_end ,
@@ -91,7 +99,7 @@ def write_context_stream(node_variable: Dict, workflow_variable: Dict, node: INo
9199 node_variable ['is_interrupt_exec' ] = is_interrupt_exec
92100 node_variable ['child_node' ] = node_child_node
93101 node_variable ['application_node_dict' ] = application_node_dict
94- _write_context (node_variable , workflow_variable , node , workflow , answer )
102+ _write_context (node_variable , workflow_variable , node , workflow , answer , reasoning_content )
95103
96104
97105def write_context (node_variable : Dict , workflow_variable : Dict , node : INode , workflow ):
@@ -106,7 +114,8 @@ def write_context(node_variable: Dict, workflow_variable: Dict, node: INode, wor
106114 node_variable ['result' ] = {'usage' : {'completion_tokens' : response .get ('completion_tokens' ),
107115 'prompt_tokens' : response .get ('prompt_tokens' )}}
108116 answer = response .get ('content' , '' ) or "抱歉,没有查找到相关内容,请重新描述您的问题或提供更多信息。"
109- _write_context (node_variable , workflow_variable , node , workflow , answer )
117+ reasoning_content = response .get ('reasoning_content' , '' )
118+ _write_context (node_variable , workflow_variable , node , workflow , answer , reasoning_content )
110119
111120
112121def reset_application_node_dict (application_node_dict , runtime_node_id , node_data ):
@@ -139,18 +148,21 @@ def get_answer_list(self) -> List[Answer] | None:
139148 if application_node_dict is None or len (application_node_dict ) == 0 :
140149 return [
141150 Answer (self .answer_text , self .view_type , self .runtime_node_id , self .workflow_params ['chat_record_id' ],
142- self .context .get ('child_node' ))]
151+ self .context .get ('child_node' ), self . runtime_node_id , '' )]
143152 else :
144153 return [Answer (n .get ('content' ), n .get ('view_type' ), self .runtime_node_id ,
145154 self .workflow_params ['chat_record_id' ], {'runtime_node_id' : n .get ('runtime_node_id' ),
146155 'chat_record_id' : n .get ('chat_record_id' )
147- , 'child_node' : n .get ('child_node' )}) for n in
156+ , 'child_node' : n .get ('child_node' )}, n .get ('real_node_id' ), n .get ('reasoning_content' ))
157+ for n in
148158 sorted (application_node_dict .values (), key = lambda item : item .get ('index' ))]
149159
150160 def save_context (self , details , workflow_manage ):
151161 self .context ['answer' ] = details .get ('answer' )
162+ self .context ['result' ] = details .get ('answer' )
152163 self .context ['question' ] = details .get ('question' )
153164 self .context ['type' ] = details .get ('type' )
165+ self .context ['reasoning_content' ] = details .get ('reasoning_content' )
154166 self .answer_text = details .get ('answer' )
155167
156168 def execute (self , application_id , message , chat_id , chat_record_id , stream , re_chat , client_id , client_type ,
@@ -229,6 +241,7 @@ def get_details(self, index: int, **kwargs):
229241 'run_time' : self .context .get ('run_time' ),
230242 'question' : self .context .get ('question' ),
231243 'answer' : self .context .get ('answer' ),
244+ 'reasoning_content' : self .context .get ('reasoning_content' ),
232245 'type' : self .node .type ,
233246 'message_tokens' : self .context .get ('message_tokens' ),
234247 'answer_tokens' : self .context .get ('answer_tokens' ),
0 commit comments