@@ -233,7 +233,7 @@ def _usage_from_context(workflow_context):
233233 return {"prompt_tokens" : prompt_tokens , "completion_tokens" : completion_tokens }
234234
235235 @staticmethod
236- def update_chat_record (chat_user_id , chat_record_id , workflow_context , messages ):
236+ def update_chat_record (chat_user_id , chat_record_id , workflow_context , messages , details ):
237237 usage = ChatSerializers ._usage_from_context (workflow_context )
238238 message_tokens = usage ["prompt_tokens" ]
239239 answer_tokens = usage ["completion_tokens" ]
@@ -243,6 +243,7 @@ def update_chat_record(chat_user_id, chat_record_id, workflow_context, messages)
243243 messages = messages ,
244244 message_tokens = message_tokens ,
245245 answer_tokens = answer_tokens ,
246+ details = details ,
246247 )
247248
248249 # ---------- 执行 ----------
@@ -327,7 +328,13 @@ def on_complete(wf_manage, error):
327328 FailureContent (str (uuid_utils .uuid7 ()), str (error ), Status .SUCCESS , None , None ).to_dict (),
328329 )
329330 messages = aggregation .get_contents ()
330- self .update_chat_record (chat_user_id , chat_record_id_str , wf_manage .context , messages )
331+ old_details = None
332+ if chat_record_id is not None :
333+ chat_record = QuerySet (ChatRecord ).filter (id = chat_record_id ).first ()
334+ if chat_record :
335+ old_details = chat_record .details
336+ details = wf_manage .get_details (position = position , old_details = old_details )
337+ self .update_chat_record (chat_user_id , chat_record_id_str , wf_manage .context , messages , details )
331338 ChatCountSerializer (data = {"chat_id" : chat_id }).update_chat ()
332339 ChatHistory (chat_id ).append (
333340 ChatRecord (
0 commit comments