|
@@ -188,6 +188,7 @@ class MyCall(pj.Call):
|
|
|
self.device_id = kwargs.get('variable_sip_h_P-LIBRA-DeviceId')
|
|
|
self.call_phone = kwargs.get("Caller-Caller-ID-Number")
|
|
|
self.logger.info("self.session_id:%s, self.call_phone:%s", self.session_id,self.call_phone)
|
|
|
+ self.taskId = "10001"
|
|
|
# self.scripts = build_demo_script()
|
|
|
self.user_asr_text_queue = queue.Queue(maxsize=100)
|
|
|
self.message_queue = queue.Queue(maxsize=3)
|
|
@@ -205,6 +206,7 @@ class MyCall(pj.Call):
|
|
|
self.asr = TestSt(call_id, message_receiver=self.on_receiver_asr_result) # 创建ASR实例
|
|
|
self.asr.start() # 启动ASR线程
|
|
|
|
|
|
+ self.start_time = time.time() # 当前机器人对话开始时间
|
|
|
|
|
|
# 超时设置
|
|
|
self.play_start_time = time.time() # 倒计时开始时间
|
|
@@ -213,6 +215,7 @@ class MyCall(pj.Call):
|
|
|
self.txtLock = False
|
|
|
self.inputLongStart = time.time() #长按键开始时间
|
|
|
|
|
|
+ self.inter_action_total = 0
|
|
|
|
|
|
|
|
|
def wait_time_check(self, current_time, wait_time):
|
|
@@ -229,6 +232,7 @@ class MyCall(pj.Call):
|
|
|
if elapsed_time > wait_time:
|
|
|
# self.user_asr_text_queue.put("ASR408error")
|
|
|
self.chat('ASR408error')
|
|
|
+ registry.BOT_ASR_408.labels(self.taskId).inc()
|
|
|
except ValueError as e:
|
|
|
self.logger.info(f"无效的等待时间参数: {wait_time}, 错误: {e}")
|
|
|
self.reset_wait_time()
|
|
@@ -340,9 +344,7 @@ class MyCall(pj.Call):
|
|
|
self.say_end_action(self.action)
|
|
|
|
|
|
def bot_say_hello(self):
|
|
|
- # print('bot_say_hello, come in ')
|
|
|
self.chat(user_asr_text="start")
|
|
|
-
|
|
|
def chat(self, user_asr_text=None):
|
|
|
# 调用文本机器人接口
|
|
|
ToTextBotAgent(user_asr_text,self)
|
|
@@ -352,10 +354,16 @@ class MyCall(pj.Call):
|
|
|
action_code = action.action_code
|
|
|
if action_code == 'hang': # 挂断
|
|
|
self.agent.hangup(self.user_part)
|
|
|
+ self.end_statistics()
|
|
|
elif action_code == 'transfer': # 转人工
|
|
|
self.agent.transfer(user_part=self.user_part, call_id=self.session_id, device_id=self.device_id)
|
|
|
+ self.end_statistics()
|
|
|
#更新通话记录
|
|
|
self.agent.dataHandleServer.update_record(self.session_id, service_category=2)
|
|
|
+ def end_statistics(self):
|
|
|
+ latency = (time.time() - self.start_time)
|
|
|
+ registry.BOT_CALL_DURATION.labels(self.taskId).observe(latency)
|
|
|
+ registry.BOT_INTERACTION_ROUNDS.labels(self.taskId).inc(self.inter_action_total)
|
|
|
|
|
|
class ToTextBotAgent:
|
|
|
def __init__(self, user_asr_text, call_agent):
|
|
@@ -368,11 +376,13 @@ class ToTextBotAgent:
|
|
|
userId=self.call_agent.call_phone,
|
|
|
sessionId= self.call_agent.session_id,
|
|
|
recordId="",
|
|
|
- taskId="10001",
|
|
|
+ taskId=self.call_agent.taskId,
|
|
|
asrText=user_asr_text,
|
|
|
ext= None
|
|
|
)
|
|
|
self.call_agent.logger.info("user_asr_text发送结果: %s", user_asr_text)
|
|
|
+ if user_asr_text != 'ASR408error':
|
|
|
+ self.call_agent.inter_action_total += 1
|
|
|
# 发送请求并处理响应
|
|
|
# self.test_request(self.request_data)
|
|
|
self.to_quest(self.request_data)
|
|
@@ -382,7 +392,7 @@ class ToTextBotAgent:
|
|
|
headers = {'Content-Type': 'application/json'}
|
|
|
request_data = request.to_json_string()
|
|
|
url = f"http://{SERVE_HOST}:40072/botservice"
|
|
|
-
|
|
|
+ start_time = time.time()
|
|
|
self.call_agent.logger.info(f"请求数据:{request_data},url:{url}")
|
|
|
try:
|
|
|
response = requests.post(url=url, json=json.loads(request_data), headers=headers, timeout=10) # 使用占位URL
|
|
@@ -400,6 +410,10 @@ class ToTextBotAgent:
|
|
|
self.call_agent.logger.info(f"请求失败,状态码: {response.status_code}, 响应内容: {response.text}")
|
|
|
except requests.RequestException as e:
|
|
|
self.call_agent.logger.info(f"请求发生异常: {e}")
|
|
|
+ finally:
|
|
|
+ latency = (time.time() - start_time)
|
|
|
+ registry.BOT_REQUEST_COUNT.inc()
|
|
|
+ registry.BOT_REQUEST_LATENCY.labels(request.taskId).observe(latency)
|
|
|
|
|
|
|
|
|
# 模拟接口请求返回
|