Skip to content

Commit

Permalink
Merge pull request Ikaros-521#553 from Ikaros-521/owner
Browse files Browse the repository at this point in the history
异常报警新增 开始报警错误数、自动重启错误数的配置项,优化报警逻辑。 页面配置 新增 自动运行 功能
  • Loading branch information
Ikaros-521 authored Jan 4, 2024
2 parents 92bd90d + 306dcf5 commit 56c2113
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 9 deletions.
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,31 +973,43 @@
"abnormal_alarm": {
"platform": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/platform"
},
"llm": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/llm"
},
"tts": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/tts"
},
"svc": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/svc"
},
"visual_body": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"other": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警"
}
Expand Down Expand Up @@ -1047,6 +1059,7 @@
"ip": "127.0.0.1",
"port": 8081,
"title": "AI Vtuber",
"auto_run": false,
"theme": {
"choose": "默认黑白",
"list": {
Expand Down
13 changes: 13 additions & 0 deletions config.json.bak
Original file line number Diff line number Diff line change
Expand Up @@ -973,31 +973,43 @@
"abnormal_alarm": {
"platform": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/platform"
},
"llm": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/llm"
},
"tts": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/tts"
},
"svc": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警/svc"
},
"visual_body": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警"
},
"other": {
"enable": true,
"start_alarm_error_num": 5,
"auto_restart_error_num": 10,
"type": "local_audio",
"local_audio_path": "data/异常报警"
}
Expand Down Expand Up @@ -1047,6 +1059,7 @@
"ip": "127.0.0.1",
"port": 8081,
"title": "AI Vtuber",
"auto_run": false,
"theme": {
"choose": "默认黑白",
"list": {
Expand Down
27 changes: 24 additions & 3 deletions utils/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ async def voice_change(self, voice_tmp_path):
logging.info(f"so_vits_svc合成成功,输出到={voice_tmp_path}")
else:
logging.error(f"so_vits_svc合成失败,请检查配置")
self.abnormal_alarm_handle("svc")
Audio.abnormal_alarm_data["svc"]["error_count"] += 1
self.abnormal_alarm_handle("svc")

return None

return voice_tmp_path
Expand Down Expand Up @@ -680,8 +681,9 @@ async def voice_change_and_put_to_queue(message, voice_tmp_path):

if voice_tmp_path is None:
logging.error(f"{message['tts_type']}合成失败,请排查配置、网络等问题")
self.abnormal_alarm_handle("tts")
Audio.abnormal_alarm_data["tts"]["error_count"] += 1
self.abnormal_alarm_handle("tts")

return False

logging.info(f"{message['tts_type']}合成成功,合成内容:【{message['content']}】,输出到={voice_tmp_path}")
Expand Down Expand Up @@ -1328,8 +1330,9 @@ async def voice_change_and_put_to_queue(voice_tmp_path):

if voice_tmp_path is None:
logging.error(f"{audio_synthesis_type}合成失败,请排查配置、网络等问题")
self.abnormal_alarm_handle("tts")
Audio.abnormal_alarm_data["tts"]["error_count"] += 1
self.abnormal_alarm_handle("tts")

return

logging.info(f"{audio_synthesis_type}合成成功,合成内容:【{content}】,输出到={voice_tmp_path}")
Expand Down Expand Up @@ -1381,6 +1384,23 @@ def abnormal_alarm_handle(self, type):
return True

if self.config.get("abnormal_alarm", type, "type") == "local_audio":
# 是否错误数大于 自动重启错误数
if Audio.abnormal_alarm_data[type]["error_count"] > self.config.get("abnormal_alarm", type, "auto_restart_error_num"):
logging.warning(f"【异常报警-{type}】 出错数超过自动重启错误数,即将自动重启")
data = {
"type": "restart",
"api_type": "api",
"data": {
"config_path": "config.json"
}
}

self.common.send_request(f'http://{self.config.get("webui", "ip")}:{self.config.get("webui", "port")}/sys_cmd', "POST", data)

# 是否错误数小于 开始报警错误数,是则不触发报警
if Audio.abnormal_alarm_data[type]["error_count"] < self.config.get("abnormal_alarm", type, "start_alarm_error_num"):
return

path_list = self.common.get_all_file_paths(self.config.get("abnormal_alarm", type, "local_audio_path"))

# 随机选择列表中的一个元素
Expand All @@ -1398,6 +1418,7 @@ def abnormal_alarm_handle(self, type):
logging.warning(f"【异常报警-{type}{self.common.extract_filename(audio_path, False)}")

self.audio_synthesis(data_json)

except Exception as e:
logging.error(traceback.format_exc())

Expand Down
23 changes: 20 additions & 3 deletions utils/my_handle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, threading, json, random
import os, sys, threading, json, random
import difflib
import logging
from datetime import datetime
Expand Down Expand Up @@ -1019,8 +1019,8 @@ def llm_handle(self, chat_type, data):
resp_content = chat_model_methods.get(chat_type, lambda: data["content"])()

if resp_content is None:
self.abnormal_alarm_handle("llm")
My_handle.abnormal_alarm_data["llm"]["error_count"] += 1
self.abnormal_alarm_handle("llm")

return resp_content

Expand Down Expand Up @@ -2064,7 +2064,7 @@ def get_interval(self, timer_flag):

"""
异常报警
"""
"""
def abnormal_alarm_handle(self, type):
"""异常报警
Expand All @@ -2080,6 +2080,22 @@ def abnormal_alarm_handle(self, type):
return True

if My_handle.config.get("abnormal_alarm", type, "type") == "local_audio":
# 是否错误数大于 自动重启错误数
if My_handle.abnormal_alarm_data[type]["error_count"] > My_handle.config.get("abnormal_alarm", type, "auto_restart_error_num"):
data = {
"type": "restart",
"api_type": "api",
"data": {
"config_path": "config.json"
}
}

My_handle.common.send_request(f'http://{My_handle.config.get("webui", "ip")}:{My_handle.config.get("webui", "port")}/sys_cmd', "POST", data)

# 是否错误数小于 开始报警错误数,是则不触发报警
if My_handle.abnormal_alarm_data[type]["error_count"] < My_handle.config.get("abnormal_alarm", type, "start_alarm_error_num"):
return

path_list = My_handle.common.get_all_file_paths(My_handle.config.get("abnormal_alarm", type, "local_audio_path"))

# 随机选择列表中的一个元素
Expand All @@ -2097,6 +2113,7 @@ def abnormal_alarm_handle(self, type):
logging.warning(f"【异常报警-{type}{My_handle.common.extract_filename(audio_path, False)}")

self.audio_synthesis_handle(message)

except Exception as e:
logging.error(traceback.format_exc())

Expand Down
Loading

0 comments on commit 56c2113

Please sign in to comment.