mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
fix:连接manager后无法使用functioncallbug
This commit is contained in:
parent
056659304a
commit
5babc3055f
4 changed files with 19 additions and 7 deletions
|
|
@ -104,8 +104,6 @@ class ConnectionHandler:
|
||||||
|
|
||||||
self.close_after_chat = False # 是否在聊天结束后关闭连接
|
self.close_after_chat = False # 是否在聊天结束后关闭连接
|
||||||
self.use_function_call_mode = False
|
self.use_function_call_mode = False
|
||||||
if self.config["selected_module"]["Intent"] == "function_call":
|
|
||||||
self.use_function_call_mode = True
|
|
||||||
|
|
||||||
async def handle_connection(self, ws):
|
async def handle_connection(self, ws):
|
||||||
try:
|
try:
|
||||||
|
|
@ -287,10 +285,17 @@ class ConnectionHandler:
|
||||||
self.memory.init_memory(device_id, self.llm)
|
self.memory.init_memory(device_id, self.llm)
|
||||||
|
|
||||||
def _initialize_intent(self):
|
def _initialize_intent(self):
|
||||||
|
if (
|
||||||
|
self.config["Intent"][self.config["selected_module"]["Intent"]]["type"]
|
||||||
|
== "function_call"
|
||||||
|
):
|
||||||
|
self.use_function_call_mode = True
|
||||||
"""初始化意图识别模块"""
|
"""初始化意图识别模块"""
|
||||||
# 获取意图识别配置
|
# 获取意图识别配置
|
||||||
intent_config = self.config["Intent"]
|
intent_config = self.config["Intent"]
|
||||||
intent_type = self.config["selected_module"]["Intent"]
|
intent_type = self.config["Intent"][self.config["selected_module"]["Intent"]][
|
||||||
|
"type"
|
||||||
|
]
|
||||||
|
|
||||||
# 如果使用 nointent,直接返回
|
# 如果使用 nointent,直接返回
|
||||||
if intent_type == "nointent":
|
if intent_type == "nointent":
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,9 @@ class FunctionHandler:
|
||||||
|
|
||||||
def register_config_functions(self):
|
def register_config_functions(self):
|
||||||
"""注册配置中的函数,可以不同客户端使用不同的配置"""
|
"""注册配置中的函数,可以不同客户端使用不同的配置"""
|
||||||
for func in self.config["Intent"]["function_call"].get("functions", []):
|
for func in self.config["Intent"][self.config["selected_module"]["Intent"]].get(
|
||||||
|
"functions", []
|
||||||
|
):
|
||||||
self.function_registry.register_function(func)
|
self.function_registry.register_function(func)
|
||||||
|
|
||||||
"""home assistant需要初始化提示词"""
|
"""home assistant需要初始化提示词"""
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ class VADProvider(VADProviderBase):
|
||||||
audio_tensor = torch.from_numpy(audio_float32)
|
audio_tensor = torch.from_numpy(audio_float32)
|
||||||
|
|
||||||
# 检测语音活动
|
# 检测语音活动
|
||||||
|
with torch.no_grad():
|
||||||
speech_prob = self.model(audio_tensor, 16000).item()
|
speech_prob = self.model(audio_tensor, 16000).item()
|
||||||
client_have_voice = speech_prob >= self.vad_threshold
|
client_have_voice = speech_prob >= self.vad_threshold
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@ HASS_CACHE = {}
|
||||||
|
|
||||||
def append_devices_to_prompt(conn):
|
def append_devices_to_prompt(conn):
|
||||||
if conn.use_function_call_mode:
|
if conn.use_function_call_mode:
|
||||||
funcs = conn.config["Intent"]["function_call"].get("functions", [])
|
funcs = conn.config["Intent"][conn.config["selected_module"]["Intent"]].get(
|
||||||
|
"functions", []
|
||||||
|
)
|
||||||
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
||||||
prompt = "下面是我家智能设备,可以通过homeassistant控制\n"
|
prompt = "下面是我家智能设备,可以通过homeassistant控制\n"
|
||||||
devices = conn.config["plugins"]["home_assistant"].get("devices", [])
|
devices = conn.config["plugins"]["home_assistant"].get("devices", [])
|
||||||
|
|
@ -26,7 +28,9 @@ def initialize_hass_handler(conn):
|
||||||
global HASS_CACHE
|
global HASS_CACHE
|
||||||
if HASS_CACHE == {}:
|
if HASS_CACHE == {}:
|
||||||
if conn.use_function_call_mode:
|
if conn.use_function_call_mode:
|
||||||
funcs = conn.config["Intent"]["function_call"].get("functions", [])
|
funcs = conn.config["Intent"][conn.config["selected_module"]["Intent"]].get(
|
||||||
|
"functions", []
|
||||||
|
)
|
||||||
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
if "hass_get_state" in funcs or "hass_set_state" in funcs:
|
||||||
HASS_CACHE["base_url"] = conn.config["plugins"]["home_assistant"].get(
|
HASS_CACHE["base_url"] = conn.config["plugins"]["home_assistant"].get(
|
||||||
"base_url"
|
"base_url"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue