@@ -117,6 +117,7 @@ def __init__(self, flow: Workflow, params, work_flow_post_handler: WorkFlowPostH
117117 self .params = params
118118 self .flow = flow
119119 self .context = {}
120+ self .chat_context = {}
120121 self .node_chunk_manage = NodeChunkManage (self )
121122 self .work_flow_post_handler = work_flow_post_handler
122123 self .current_node = None
@@ -131,6 +132,7 @@ def __init__(self, flow: Workflow, params, work_flow_post_handler: WorkFlowPostH
131132 self .lock = threading .Lock ()
132133 self .field_list = []
133134 self .global_field_list = []
135+ self .chat_field_list = []
134136 self .init_fields ()
135137 if start_node_id is not None :
136138 self .load_node (chat_record , start_node_id , start_node_data )
@@ -140,6 +142,7 @@ def __init__(self, flow: Workflow, params, work_flow_post_handler: WorkFlowPostH
140142 def init_fields (self ):
141143 field_list = []
142144 global_field_list = []
145+ chat_field_list = []
143146 for node in self .flow .nodes :
144147 properties = node .properties
145148 node_name = properties .get ('stepName' )
@@ -154,10 +157,16 @@ def init_fields(self):
154157 if global_fields is not None :
155158 for global_field in global_fields :
156159 global_field_list .append ({** global_field , 'node_id' : node_id , 'node_name' : node_name })
160+ chat_fields = node_config .get ('chatFields' )
161+ if chat_fields is not None :
162+ for chat_field in chat_fields :
163+ chat_field_list .append ({** chat_field , 'node_id' : node_id , 'node_name' : node_name })
157164 field_list .sort (key = lambda f : len (f .get ('node_name' ) + f .get ('value' )), reverse = True )
158165 global_field_list .sort (key = lambda f : len (f .get ('node_name' ) + f .get ('value' )), reverse = True )
166+ chat_field_list .sort (key = lambda f : len (f .get ('node_name' ) + f .get ('value' )), reverse = True )
159167 self .field_list = field_list
160168 self .global_field_list = global_field_list
169+ self .chat_field_list = chat_field_list
161170
162171 def append_answer (self , content ):
163172 self .answer += content
@@ -445,6 +454,9 @@ def is_result(self, current_node, current_node_result):
445454 return current_node .node_params .get ('is_result' , not self ._has_next_node (
446455 current_node , current_node_result )) if current_node .node_params is not None else False
447456
457+ def get_chat_info (self ):
458+ return self .work_flow_post_handler .chat_info
459+
448460 def get_chunk_content (self , chunk , is_end = False ):
449461 return 'data: ' + json .dumps (
450462 {'chat_id' : self .params ['chat_id' ], 'id' : self .params ['chat_record_id' ], 'operate' : True ,
@@ -587,12 +599,15 @@ def get_reference_field(self, node_id: str, fields: List[str]):
587599 """
588600 if node_id == 'global' :
589601 return INode .get_field (self .context , fields )
602+ elif node_id == 'chat' :
603+ return INode .get_field (self .chat_context , fields )
590604 else :
591605 return self .get_node_by_id (node_id ).get_reference_field (fields )
592606
593607 def get_workflow_content (self ):
594608 context = {
595609 'global' : self .context ,
610+ 'chat' : self .chat_context
596611 }
597612
598613 for node in self .node_context :
@@ -610,6 +625,10 @@ def reset_prompt(self, prompt: str):
610625 globeLabelNew = f"global.{ field .get ('value' )} "
611626 globeValue = f"context.get('global').get('{ field .get ('value' , '' )} ','')"
612627 prompt = prompt .replace (globeLabel , globeValue ).replace (globeLabelNew , globeValue )
628+ for field in self .chat_field_list :
629+ chatLabel = f"chat.{ field .get ('value' )} "
630+ chatValue = f"context.get('chat').get('{ field .get ('value' , '' )} ','')"
631+ prompt = prompt .replace (chatLabel , chatValue )
613632 return prompt
614633
615634 def generate_prompt (self , prompt : str ):
0 commit comments