@@ -515,7 +515,8 @@ def format_record(record: ChatRecordResult):
515515 return _dict
516516
517517
518- def get_chat_log_history (session : SessionDep , chat_record_id : int , current_user : CurrentUser , without_steps : bool = False ) -> ChatLogHistory :
518+ def get_chat_log_history (session : SessionDep , chat_record_id : int , current_user : CurrentUser ,
519+ without_steps : bool = False ) -> ChatLogHistory :
519520 """
520521 获取ChatRecord的详细历史记录
521522
@@ -573,6 +574,7 @@ def get_chat_log_history(session: SessionDep, chat_record_id: int, current_user:
573574
574575 # 获取操作类型的枚举名称
575576 operate_name = None
577+ message = None
576578 if log .operate :
577579 # 如果是OperationEnum枚举实例
578580 if isinstance (log .operate , OperationEnum ):
@@ -590,14 +592,24 @@ def get_chat_log_history(session: SessionDep, chat_record_id: int, current_user:
590592 else :
591593 operate_name = str (log .operate )
592594
595+ if log .messages is not None :
596+ message = log .messages
597+ if not log .operate == OperationEnum .CHOOSE_TABLE :
598+ try :
599+ message = orjson .loads (log .messages )
600+ except Exception :
601+ pass
602+
593603 # 创建ChatLogHistoryItem
594604 history_item = ChatLogHistoryItem (
595605 start_time = log .start_time ,
596606 finish_time = log .finish_time ,
597607 duration = duration ,
598608 total_tokens = log_tokens ,
599609 operate = operate_name ,
600- local_operation = log .local_operation
610+ local_operation = log .local_operation ,
611+ error = log .error ,
612+ message = message ,
601613 )
602614
603615 steps .append (history_item )
@@ -622,6 +634,7 @@ def get_chat_log_history(session: SessionDep, chat_record_id: int, current_user:
622634
623635 return chat_log_history
624636
637+
625638def get_chat_brief_generate (session : SessionDep , chat_id : int ):
626639 chat = get_chat (session = session , chat_id = chat_id )
627640 if chat is not None and chat .brief_generate is not None :
@@ -1055,7 +1068,8 @@ def save_error_message(session: SessionDep, record_id: int, message: str) -> Cha
10551068
10561069 # log error finish
10571070 stmt = update (ChatLog ).where (and_ (ChatLog .pid == record .id , ChatLog .finish_time .is_ (None ))).values (
1058- finish_time = record .finish_time
1071+ finish_time = record .finish_time ,
1072+ error = True
10591073 )
10601074 session .execute (stmt )
10611075 session .commit ()
0 commit comments