@@ -94,12 +94,27 @@ def handler(self,
9494 return PostHandler ()
9595
9696
97+ class DebugChatSerializers (serializers .Serializer ):
98+ chat_id = serializers .UUIDField (required = True , label = _ ("Conversation ID" ))
99+
100+ def chat (self , instance : dict , base_to_response : BaseToResponse = SystemToResponse ()):
101+ self .is_valid (raise_exception = True )
102+ chat_id = self .data .get ('chat_id' )
103+ chat_info : ChatInfo = ChatInfo .get_cache (chat_id )
104+ return ChatSerializers (data = {
105+ 'chat_id' : chat_id , "chat_user_id" : chat_info .chat_user_id ,
106+ "chat_user_type" : chat_info .chat_user_type ,
107+ "application_id" : chat_info .application .id , "debug" : True
108+ }).chat (instance , base_to_response )
109+
110+
97111class ChatSerializers (serializers .Serializer ):
98112 chat_id = serializers .UUIDField (required = True , label = _ ("Conversation ID" ))
99113 chat_user_id = serializers .CharField (required = True , label = _ ("Client id" ))
100114 chat_user_type = serializers .CharField (required = True , label = _ ("Client Type" ))
101115 application_id = serializers .UUIDField (required = True , allow_null = True ,
102116 label = _ ("Application ID" ))
117+ debug = serializers .BooleanField (required = False , label = _ ("Debug" ))
103118
104119 def is_valid_application_workflow (self , * , raise_exception = False ):
105120 self .is_valid_intraday_access_num ()
@@ -158,6 +173,7 @@ def chat_simple(self, chat_info: ChatInfo, instance, base_to_response):
158173 .append_step (BaseGenerateHumanMessageStep )
159174 .append_step (BaseChatStep )
160175 .add_base_to_response (base_to_response )
176+ .add_debug (self .data .get ('debug' , False ))
161177 .build ())
162178 exclude_paragraph_id_list = []
163179 # 相同问题是否需要排除已经查询到的段落
@@ -189,18 +205,18 @@ def get_chat_record(chat_info, chat_record_id):
189205 return chat_record
190206
191207 def chat_work_flow (self , chat_info : ChatInfo , instance : dict , base_to_response ):
192- message = self . data .get ('message' )
193- re_chat = self . data .get ('re_chat' )
194- stream = self . data .get ('stream' )
195- chat_user_id = instance . get (' chat_user_id' )
196- chat_user_type = instance .get ('chat_user_type' )
197- form_data = self . data .get ('form_data' )
198- image_list = self . data .get ('image_list' )
199- document_list = self . data .get ('document_list' )
200- audio_list = self . data .get ('audio_list' )
201- other_list = self . data .get ('other_list' )
202- user_id = chat_info .application .user_id
203- chat_record_id = self . data .get ('chat_record_id' )
208+ message = instance .get ('message' )
209+ re_chat = instance .get ('re_chat' )
210+ stream = instance .get ('stream' )
211+ chat_user_id = self . data . get (" chat_user_id" )
212+ chat_user_type = self . data .get ('chat_user_type' )
213+ form_data = instance .get ('form_data' )
214+ image_list = instance .get ('image_list' )
215+ document_list = instance .get ('document_list' )
216+ audio_list = instance .get ('audio_list' )
217+ other_list = instance .get ('other_list' )
218+ workspace_id = chat_info .application .workspace_id
219+ chat_record_id = instance .get ('chat_record_id' )
204220 chat_record = None
205221 history_chat_record = chat_info .chat_record_list
206222 if chat_record_id is not None :
@@ -214,8 +230,9 @@ def chat_work_flow(self, chat_info: ChatInfo, instance: dict, base_to_response):
214230 're_chat' : re_chat ,
215231 'chat_user_id' : chat_user_id ,
216232 'chat_user_type' : chat_user_type ,
217- 'user_id' : user_id },
218- WorkFlowPostHandler (chat_info , chat_user_id , chat_user_type ),
233+ 'workspace_id' : workspace_id ,
234+ 'debug' : self .data .get ('debug' , False )},
235+ WorkFlowPostHandler (chat_info ),
219236 base_to_response , form_data , image_list , document_list , audio_list ,
220237 other_list ,
221238 self .data .get ('runtime_node_id' ),
@@ -229,7 +246,7 @@ def chat(self, instance: dict, base_to_response: BaseToResponse = SystemToRespon
229246 chat_info = self .get_chat_info ()
230247 self .is_valid_chat_id (chat_info )
231248 if chat_info .application .type == ApplicationTypeChoices .SIMPLE :
232- self .is_valid_application_simple (raise_exception = True , chat_info = chat_info ),
249+ self .is_valid_application_simple (raise_exception = True , chat_info = chat_info )
233250 return self .chat_simple (chat_info , instance , base_to_response )
234251 else :
235252 self .is_valid_application_workflow (raise_exception = True )
@@ -295,6 +312,7 @@ class OpenChatSerializers(serializers.Serializer):
295312 application_id = serializers .UUIDField (required = True )
296313 chat_user_id = serializers .CharField (required = True , label = _ ("Client id" ))
297314 chat_user_type = serializers .CharField (required = True , label = _ ("Client Type" ))
315+ debug = serializers .BooleanField (required = True , label = _ ("Debug" ))
298316
299317 def is_valid (self , * , raise_exception = False ):
300318 super ().is_valid (raise_exception = True )
@@ -317,6 +335,7 @@ def open_work_flow(self, application):
317335 application_id = self .data .get ('application_id' )
318336 chat_user_id = self .data .get ("chat_user_id" )
319337 chat_user_type = self .data .get ("chat_user_type" )
338+ debug = self .data .get ("debug" )
320339 chat_id = str (uuid .uuid7 ())
321340 work_flow_version = QuerySet (WorkFlowVersion ).filter (application_id = application_id ).order_by (
322341 '-create_time' )[0 :1 ].first ()
@@ -326,13 +345,15 @@ def open_work_flow(self, application):
326345 "The application has not been published. Please use it after publishing." ))
327346 ChatInfo (chat_id , chat_user_id , chat_user_type , [],
328347 [],
329- application , work_flow_version ).set_cache ()
348+ application_id ,
349+ application , work_flow_version , debug ).set_cache ()
330350 return chat_id
331351
332352 def open_simple (self , application ):
333353 application_id = self .data .get ('application_id' )
334354 chat_user_id = self .data .get ("chat_user_id" )
335355 chat_user_type = self .data .get ("chat_user_type" )
356+ debug = self .data .get ("debug" )
336357 knowledge_id_list = [str (row .dataset_id ) for row in
337358 QuerySet (ApplicationKnowledgeMapping ).filter (
338359 application_id = application_id )]
@@ -342,5 +363,6 @@ def open_simple(self, application):
342363 QuerySet (Document ).filter (
343364 knowledge_id__in = knowledge_id_list ,
344365 is_active = False )],
345- application ).set_cache ()
366+ application_id ,
367+ application , debug = debug ).set_cache ()
346368 return chat_id
0 commit comments