|
@@ -330,12 +330,12 @@ class DialogueManager:
|
|
|
# 默认为闲聊状态
|
|
|
return DialogueState.CHITCHAT
|
|
|
|
|
|
- def _send_human_intervention_alert(self, reason: Optional[str] = None) -> None:
|
|
|
+ def _send_alert(self, alert_type: str, reason: Optional[str] = None) -> None:
|
|
|
time_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
- staff_info = f"{self.staff_profile.get("agent_name", "未知")}[{self.staff_id}]"
|
|
|
- user_info = f"{self.user_profile.get("nickname", "未知")}[{self.user_id}]"
|
|
|
+ staff_info = f"{self.staff_profile.get('agent_name', '未知')}[{self.staff_id}]"
|
|
|
+ user_info = f"{self.user_profile.get('nickname', '未知')}[{self.user_id}]"
|
|
|
alert_message = f"""
|
|
|
- 人工介入告警
|
|
|
+ {alert_type}告警
|
|
|
员工: {staff_info}
|
|
|
用户: {user_info}
|
|
|
时间: {time_str}
|
|
@@ -357,13 +357,17 @@ class DialogueManager:
|
|
|
dialogue_to_send.append(f"[{role_map[role]}]{dialogue['content']}")
|
|
|
alert_message += '\n'.join(dialogue_to_send)
|
|
|
|
|
|
- ack_url = "http://ai-wechat-hook.piaoquantv.com/manage/insertEvent?" \
|
|
|
- f"sender={self.user_id}&receiver={self.staff_id}&type={MessageType.HUMAN_INTERVENTION_END.value}&content=OPERATION"
|
|
|
+ if alert_type == '人工介入':
|
|
|
+ ack_url = "http://ai-wechat-hook.piaoquantv.com/manage/insertEvent?" \
|
|
|
+ f"sender={self.user_id}&receiver={self.staff_id}&type={MessageType.HUMAN_INTERVENTION_END.value}&content=OPERATION"
|
|
|
+ else:
|
|
|
+ ack_url = None
|
|
|
|
|
|
LarkAlertForHumanIntervention().send_lark_alert_for_human_intervention(alert_message, ack_url)
|
|
|
- LarkSheetRecordForHumanIntervention().send_lark_sheet_record_for_human_intervention(
|
|
|
- staff_info, user_info, '\n'.join(dialogue_to_send), reason
|
|
|
- )
|
|
|
+ if alert_type == '人工介入':
|
|
|
+ LarkSheetRecordForHumanIntervention().send_lark_sheet_record_for_human_intervention(
|
|
|
+ staff_info, user_info, '\n'.join(dialogue_to_send), reason
|
|
|
+ )
|
|
|
|
|
|
def resume_from_human_intervention(self) -> None:
|
|
|
"""从人工介入状态恢复"""
|
|
@@ -381,7 +385,14 @@ class DialogueManager:
|
|
|
reason = llm_response.replace('<人工介入>', '')
|
|
|
logger.warning(f'staff[{self.staff_id}], user[{self.user_id}]: human intervention triggered, reason: {reason}')
|
|
|
self.do_state_change(DialogueState.HUMAN_INTERVENTION)
|
|
|
- self._send_human_intervention_alert(reason)
|
|
|
+ self._send_alert('人工介入', reason)
|
|
|
+ return None
|
|
|
+
|
|
|
+ if '<结束>' or '<负向情绪结束>' in llm_response:
|
|
|
+ logger.warning(f'staff[{self.staff_id}], user[{self.user_id}]: conversation ended')
|
|
|
+ self.do_state_change(DialogueState.FAREWELL)
|
|
|
+ if '<负向情绪结束>' in llm_response:
|
|
|
+ self._send_alert("用户负向情绪")
|
|
|
return None
|
|
|
|
|
|
"""根据当前状态处理LLM响应,如果处于人工介入状态则返回None"""
|