@@ -75,7 +75,15 @@ def one(self, debug):
7575 chat_record = self .get_chat_record ()
7676 if chat_record is None :
7777 raise AppApiException (500 , gettext ("Conversation does not exist" ))
78- return ApplicationChatRecordQuerySerializers .reset_chat_record (chat_record )
78+ application_access_token = QuerySet (ApplicationAccessToken ).filter (
79+ application_id = self .data .get ('application_id' )).first ()
80+ show_source = False
81+ show_exec = False
82+ if application_access_token is not None :
83+ show_exec = application_access_token .show_exec
84+ show_source = application_access_token .show_source
85+ return ApplicationChatRecordQuerySerializers .reset_chat_record (
86+ chat_record , show_source , show_exec )
7987
8088
8189class ApplicationChatRecordQuerySerializers (serializers .Serializer ):
@@ -103,21 +111,34 @@ def list(self, with_valid=True):
103111 QuerySet (ChatRecord ).filter (chat_id = self .data .get ('chat_id' )).order_by (order_by )]
104112
105113 @staticmethod
106- def reset_chat_record (chat_record ):
114+ def reset_chat_record (chat_record , show_source , show_exec ):
107115 knowledge_list = []
108116 paragraph_list = []
109-
110117 if 'search_step' in chat_record .details and chat_record .details .get ('search_step' ).get (
111118 'paragraph_list' ) is not None :
112119 paragraph_list = chat_record .details .get ('search_step' ).get (
113120 'paragraph_list' )
114- knowledge_list = [{'id' : dataset_id , 'name' : name } for dataset_id , name in reduce (lambda x , y : {** x , ** y },
115- [{row .get (
116- 'knowledge_id' ): row .get (
117- "knowledge_name" )} for
118- row in
119- paragraph_list ],
120- {}).items ()]
121+
122+ for item in chat_record .details .values ():
123+ if item .get ('type' ) == 'search-knowledge-node' and item .get ('show_knowledge' , False ):
124+ paragraph_list = paragraph_list + item .get (
125+ 'paragraph_list' )
126+
127+ if item .get ('type' ) == 'reranker-node' and item .get ('show_knowledge' , False ):
128+ paragraph_list = paragraph_list + [rl .get ('metadata' ) for rl in item .get ('result_list' ) if
129+ 'document_id' in rl .get ('metadata' ) and 'knowledge_id' in rl .get (
130+ 'metadata' )]
131+ paragraph_list = list ({p .get ('id' ): p for p in paragraph_list }.values ())
132+ knowledge_list = knowledge_list + [{'id' : knowledge_id , ** knowledge } for knowledge_id , knowledge in
133+ reduce (lambda x , y : {** x , ** y },
134+ [{row .get (
135+ 'knowledge_id' ): {'knowledge_name' : row .get (
136+ "knowledge_name" ),
137+ 'knowledge_type' : row .get ('knowledge_type' )}} for
138+ row in
139+ paragraph_list ],
140+ {}).items ()]
141+
121142 if len (chat_record .improve_paragraph_id_list ) > 0 :
122143 paragraph_model_list = QuerySet (Paragraph ).filter (id__in = chat_record .improve_paragraph_id_list )
123144 if len (paragraph_model_list ) < len (chat_record .improve_paragraph_id_list ):
@@ -126,24 +147,33 @@ def reset_chat_record(chat_record):
126147 filter (lambda p_id : paragraph_model_id_list .__contains__ (p_id ),
127148 chat_record .improve_paragraph_id_list ))
128149 chat_record .save ()
129-
150+ show_source_dict = {'knowledge_list' : knowledge_list ,
151+ 'paragraph_list' : paragraph_list , }
152+ show_exec_dict = {'execution_details' : [chat_record .details [key ] for key in chat_record .details ]}
130153 return {
131154 ** ChatRecordSerializerModel (chat_record ).data ,
132155 'padding_problem_text' : chat_record .details .get ('problem_padding' ).get (
133156 'padding_problem_text' ) if 'problem_padding' in chat_record .details else None ,
134- 'knowledge_list' : knowledge_list ,
135- 'paragraph_list' : paragraph_list ,
136- 'execution_details' : [chat_record .details [key ] for key in chat_record .details ]
157+ ** (show_source_dict if show_source else {}),
158+ ** (show_exec_dict if show_exec else {})
137159 }
138160
139161 def page (self , current_page : int , page_size : int , with_valid = True ):
140162 if with_valid :
141163 self .is_valid (raise_exception = True )
142164 order_by = '-create_time' if self .data .get ('order_asc' ) is None or self .data .get (
143165 'order_asc' ) else 'create_time'
166+ application_access_token = QuerySet (ApplicationAccessToken ).filter (
167+ application_id = self .data .get ('application_id' )).first ()
168+ show_source = False
169+ show_exec = False
170+ if application_access_token is not None :
171+ show_exec = application_access_token .show_exec
172+ show_source = application_access_token .show_source
144173 page = page_search (current_page , page_size ,
145174 QuerySet (ChatRecord ).filter (chat_id = self .data .get ('chat_id' )).order_by (order_by ),
146- post_records_handler = lambda chat_record : self .reset_chat_record (chat_record ))
175+ post_records_handler = lambda chat_record : self .reset_chat_record (chat_record , show_source ,
176+ show_exec ))
147177 return page
148178
149179
0 commit comments