mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-25 16:43:55 +08:00
Merge remote-tracking branch 'upstream/main' into update/enhance-gemini-with-proxy
This commit is contained in:
@@ -4,7 +4,7 @@ from loguru import logger
|
||||
from config.config_loader import load_config
|
||||
from config.settings import check_config_file
|
||||
|
||||
SERVER_VERSION = "0.4.2"
|
||||
SERVER_VERSION = "0.4.3"
|
||||
|
||||
|
||||
def get_module_abbreviation(module_name, module_dict):
|
||||
|
||||
@@ -75,6 +75,7 @@ class ConnectionHandler:
|
||||
self.prompt = None
|
||||
self.welcome_msg = None
|
||||
self.max_output_size = 0
|
||||
self.chat_history_conf = 0
|
||||
|
||||
# 客户端状态相关
|
||||
self.client_abort = False
|
||||
@@ -250,11 +251,15 @@ class ConnectionHandler:
|
||||
self.logger.bind(tag=TAG).info("收到服务器重启指令,准备执行...")
|
||||
|
||||
# 发送确认响应
|
||||
await self.websocket.send(json.dumps({
|
||||
"type": "server_response",
|
||||
"status": "success",
|
||||
"message": "服务器重启中..."
|
||||
}))
|
||||
await self.websocket.send(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "server_response",
|
||||
"status": "success",
|
||||
"message": "服务器重启中...",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
# 异步执行重启操作
|
||||
def restart_server():
|
||||
@@ -266,7 +271,7 @@ class ConnectionHandler:
|
||||
stdin=sys.stdin,
|
||||
stdout=sys.stdout,
|
||||
stderr=sys.stderr,
|
||||
start_new_session=True
|
||||
start_new_session=True,
|
||||
)
|
||||
os._exit(0)
|
||||
|
||||
@@ -275,11 +280,15 @@ class ConnectionHandler:
|
||||
|
||||
except Exception as e:
|
||||
self.logger.bind(tag=TAG).error(f"重启失败: {str(e)}")
|
||||
await self.websocket.send(json.dumps({
|
||||
"type": "server_response",
|
||||
"status": "error",
|
||||
"message": f"Restart failed: {str(e)}"
|
||||
}))
|
||||
await self.websocket.send(
|
||||
json.dumps(
|
||||
{
|
||||
"type": "server_response",
|
||||
"status": "error",
|
||||
"message": f"Restart failed: {str(e)}",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def _initialize_components(self):
|
||||
"""初始化组件"""
|
||||
@@ -306,6 +315,8 @@ class ConnectionHandler:
|
||||
"""初始化ASR和TTS上报线程"""
|
||||
if not self.read_config_from_api or self.need_bind:
|
||||
return
|
||||
if self.chat_history_conf == 0:
|
||||
return
|
||||
if self.tts_report_thread is None or not self.tts_report_thread.is_alive():
|
||||
self.tts_report_thread = threading.Thread(
|
||||
target=self._tts_report_worker, daemon=True
|
||||
@@ -379,7 +390,8 @@ class ConnectionHandler:
|
||||
self.config["prompt"] = private_config["prompt"]
|
||||
if private_config.get("device_max_output_size", None) is not None:
|
||||
self.max_output_size = int(private_config["device_max_output_size"])
|
||||
|
||||
if private_config.get("chat_history_conf", None) is not None:
|
||||
self.chat_history_conf = int(private_config["chat_history_conf"])
|
||||
try:
|
||||
modules = initialize_modules(
|
||||
self.logger,
|
||||
@@ -838,7 +850,7 @@ class ConnectionHandler:
|
||||
if future is None:
|
||||
continue
|
||||
text = None
|
||||
opus_datas, tts_file = [], None
|
||||
audio_datas, tts_file = [], None
|
||||
try:
|
||||
self.logger.bind(tag=TAG).debug("正在处理TTS任务...")
|
||||
tts_timeout = int(self.config.get("tts_timeout", 10))
|
||||
|
||||
@@ -92,6 +92,8 @@ def opus_to_wav(conn, opus_data):
|
||||
def enqueue_tts_report(conn, type, text, opus_data):
|
||||
if not conn.read_config_from_api or conn.need_bind:
|
||||
return
|
||||
if conn.chat_history_conf == 0:
|
||||
return
|
||||
"""将TTS数据加入上报队列
|
||||
|
||||
Args:
|
||||
@@ -101,10 +103,15 @@ def enqueue_tts_report(conn, type, text, opus_data):
|
||||
"""
|
||||
try:
|
||||
# 使用连接对象的队列,传入文本和二进制数据而非文件路径
|
||||
conn.tts_report_queue.put((type, text, opus_data))
|
||||
|
||||
conn.logger.bind(tag=TAG).debug(
|
||||
f"TTS数据已加入上报队列: {conn.device_id}, 音频大小: {len(opus_data)} "
|
||||
)
|
||||
if conn.chat_history_conf == 2:
|
||||
conn.tts_report_queue.put((type, text, opus_data))
|
||||
conn.logger.bind(tag=TAG).debug(
|
||||
f"TTS数据已加入上报队列: {conn.device_id}, 音频大小: {len(opus_data)} "
|
||||
)
|
||||
else:
|
||||
conn.tts_report_queue.put((type, text, None))
|
||||
conn.logger.bind(tag=TAG).debug(
|
||||
f"TTS数据已加入上报队列: {conn.device_id}, 不上报音频"
|
||||
)
|
||||
except Exception as e:
|
||||
conn.logger.bind(tag=TAG).error(f"加入TTS上报队列失败: {text}, {e}")
|
||||
|
||||
@@ -61,5 +61,6 @@ class LLMProvider(LLMProviderBase):
|
||||
yield "【LLM服务响应异常】"
|
||||
|
||||
def response_with_functions(self, session_id, dialogue, functions=None):
|
||||
logger.bind(tag=TAG).info(f"阿里百练暂未实现完整的工具调用(function call)")
|
||||
return self.response(session_id, dialogue)
|
||||
logger.bind(tag=TAG).error(
|
||||
f"阿里百练暂未实现完整的工具调用(function call),建议使用其他意图识别"
|
||||
)
|
||||
|
||||
@@ -66,5 +66,6 @@ class LLMProvider(LLMProviderBase):
|
||||
yield "【服务响应异常】"
|
||||
|
||||
def response_with_functions(self, session_id, dialogue, functions=None):
|
||||
logger.bind(tag=TAG).info(f"fastgpt暂未实现完整的工具调用(function call)")
|
||||
return self.response(session_id, dialogue)
|
||||
logger.bind(tag=TAG).error(
|
||||
f"fastgpt暂未实现完整的工具调用(function call),建议使用其他意图识别"
|
||||
)
|
||||
|
||||
@@ -66,7 +66,6 @@ class LLMProvider(LLMProviderBase):
|
||||
logger.bind(tag=TAG).error(f"生成响应时出错: {e}")
|
||||
|
||||
def response_with_functions(self, session_id, dialogue, functions=None):
|
||||
logger.bind(tag=TAG).info(
|
||||
f"homeassistant不支持(function call),建议使用意图识别使用:nointent"
|
||||
logger.bind(tag=TAG).error(
|
||||
f"homeassistant不支持(function call),建议使用其他意图识别"
|
||||
)
|
||||
return self.response(session_id, dialogue)
|
||||
|
||||
Reference in New Issue
Block a user