Skip to content

Commit c0cec94

Browse files
authored
fix:manager意图识别bug (xinnan-tech#762)
* fix:连接manager后无法使用functioncallbug * fix:意图识别使用llm无法播放音乐bug * fix:manager第一图识别使用独立llm无法初始化llm的bug
1 parent cf9e337 commit c0cec94

File tree

15 files changed

+107
-45
lines changed

15 files changed

+107
-45
lines changed

main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public AgentServiceImpl(AgentDao agentDao) {
4444
@Override
4545
public PageData<AgentEntity> adminAgentList(Map<String, Object> params) {
4646
IPage<AgentEntity> page = agentDao.selectPage(
47-
getPage(params, "sort", true),
47+
getPage(params, "agent_name", true),
4848
new QueryWrapper<>());
4949
return new PageData<>(page.getRecords(), page.getTotal());
5050
}

main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ private void buildModuleConfig(
231231
boolean isCache) {
232232
Map<String, String> selectedModule = new HashMap<>();
233233

234-
String[] modelTypes = { "VAD", "ASR", "LLM", "TTS", "Memory", "Intent" };
235-
String[] modelIds = { vadModelId, asrModelId, llmModelId, ttsModelId, memModelId, intentModelId };
234+
String[] modelTypes = { "VAD", "ASR", "TTS", "Memory", "Intent", "LLM" };
235+
String[] modelIds = { vadModelId, asrModelId, ttsModelId, memModelId, intentModelId, llmModelId };
236+
String intentLLMModelId = null;
236237

237238
for (int i = 0; i < modelIds.length; i++) {
238239
if (modelIds[i] == null) {
@@ -246,10 +247,27 @@ private void buildModuleConfig(
246247
if ("TTS".equals(modelTypes[i]) && voice != null) {
247248
((Map<String, Object>) model.getConfigJson()).put("private_voice", voice);
248249
}
250+
// 如果是Intent类型,且type=intent_llm,则给他添加附加模型
251+
if ("Intent".equals(modelTypes[i])) {
252+
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
253+
if ("intent_llm".equals(map.get("type"))) {
254+
intentLLMModelId = (String) map.get("llm");
255+
if (intentLLMModelId != null && intentLLMModelId.equals(llmModelId)) {
256+
intentLLMModelId = null;
257+
}
258+
}
259+
}
260+
// 如果是LLM类型,且intentLLMModelId不为空,则添加附加模型
261+
if ("LLM".equals(modelTypes[i]) && intentLLMModelId != null) {
262+
ModelConfigEntity intentLLM = modelConfigService.getModelById(intentLLMModelId, isCache);
263+
typeConfig.put(intentLLM.getId(), intentLLM.getConfigJson());
264+
}
249265
}
250266
result.put(modelTypes[i], typeConfig);
267+
251268
selectedModule.put(modelTypes[i], model.getId());
252269
}
270+
253271
result.put("selected_module", selectedModule);
254272
if (StringUtils.isNotBlank(prompt)) {
255273
prompt = prompt.replace("{{assistant_name}}", "小智");

main/manager-api/src/main/java/xiaozhi/modules/device/service/impl/DeviceServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public PageData<UserShowDeviceListVO> page(DevicePageUserDTO dto) {
221221
params.put(Constant.PAGE, dto.getPage());
222222
params.put(Constant.LIMIT, dto.getLimit());
223223
IPage<DeviceEntity> page = baseDao.selectPage(
224-
getPage(params, "sort", true),
224+
getPage(params, "mac_address", true),
225225
// 定义查询条件
226226
new QueryWrapper<DeviceEntity>()
227227
// 必须设备关键词查找

main/manager-api/src/main/java/xiaozhi/modules/sys/service/impl/SysParamsServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
3737
@Override
3838
public PageData<SysParamsDTO> page(Map<String, Object> params) {
3939
IPage<SysParamsEntity> page = baseDao.selectPage(
40-
getPage(params, Constant.CREATE_DATE, false),
40+
getPage(params, null, false),
4141
getWrapper(params));
4242

4343
return getPageData(page, SysParamsDTO.class);

main/manager-api/src/main/java/xiaozhi/modules/timbre/service/impl/TimbreServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public PageData<TimbreDetailsVO> page(TimbrePageDTO dto) {
4747
params.put(Constant.PAGE, dto.getPage());
4848
params.put(Constant.LIMIT, dto.getLimit());
4949
IPage<TimbreEntity> page = baseDao.selectPage(
50-
getPage(params, "sort", true),
50+
getPage(params, null, true),
5151
// 定义查询条件
5252
new QueryWrapper<TimbreEntity>()
5353
// 必须按照ttsID查找
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- 对0.3.0版本之前的参数进行修改
2+
update `sys_params` set param_value = '.mp3;.wav;.p3' where param_code = 'plugins.play_music.music_ext';
3+
update `ai_model_config` set config_json = '{\"type\": \"intent_llm\", \"llm\": \"LLM_ChatGLMLLM\"}' where id = 'Intent_intent_llm';

main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ databaseChangeLog:
5050
changes:
5151
- sqlFile:
5252
encoding: utf8
53-
path: classpath:db/changelog/202504112058.sql
53+
path: classpath:db/changelog/202504112058.sql
54+
- changeSet:
55+
id: 202504131542
56+
author: John
57+
changes:
58+
- sqlFile:
59+
encoding: utf8
60+
path: classpath:db/changelog/202504131542.sql

main/xiaozhi-server/core/connection.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def __init__(
104104

105105
self.close_after_chat = False # 是否在聊天结束后关闭连接
106106
self.use_function_call_mode = False
107-
if self.config["selected_module"]["Intent"] == "function_call":
108-
self.use_function_call_mode = True
109107

110108
async def handle_connection(self, ws):
111109
try:
@@ -222,37 +220,37 @@ def _initialize_models(self):
222220
)
223221
if private_config.get("VAD", None) is not None:
224222
init_vad = True
225-
self.config["vad"] = private_config["VAD"]
223+
self.config["VAD"] = private_config["VAD"]
226224
self.config["selected_module"]["VAD"] = private_config["selected_module"][
227225
"VAD"
228226
]
229227
if private_config.get("ASR", None) is not None:
230228
init_asr = True
231-
self.config["asr"] = private_config["ASR"]
229+
self.config["ASR"] = private_config["ASR"]
232230
self.config["selected_module"]["ASR"] = private_config["selected_module"][
233231
"ASR"
234232
]
235233
if private_config.get("LLM", None) is not None:
236234
init_llm = True
237-
self.config["llm"] = private_config["LLM"]
235+
self.config["LLM"] = private_config["LLM"]
238236
self.config["selected_module"]["LLM"] = private_config["selected_module"][
239237
"LLM"
240238
]
241239
if private_config.get("TTS", None) is not None:
242240
init_tts = True
243-
self.config["tts"] = private_config["TTS"]
241+
self.config["TTS"] = private_config["TTS"]
244242
self.config["selected_module"]["TTS"] = private_config["selected_module"][
245243
"TTS"
246244
]
247245
if private_config.get("Memory", None) is not None:
248246
init_memory = True
249-
self.config["memory"] = private_config["Memory"]
247+
self.config["Memory"] = private_config["Memory"]
250248
self.config["selected_module"]["Memory"] = private_config[
251249
"selected_module"
252250
]["Memory"]
253251
if private_config.get("Intent", None) is not None:
254252
init_intent = True
255-
self.config["intent"] = private_config["Intent"]
253+
self.config["Intent"] = private_config["Intent"]
256254
self.config["selected_module"]["Intent"] = private_config[
257255
"selected_module"
258256
]["Intent"]
@@ -287,17 +285,26 @@ def _initialize_memory(self):
287285
self.memory.init_memory(device_id, self.llm)
288286

289287
def _initialize_intent(self):
288+
if (
289+
self.config["Intent"][self.config["selected_module"]["Intent"]]["type"]
290+
== "function_call"
291+
):
292+
self.use_function_call_mode = True
290293
"""初始化意图识别模块"""
291294
# 获取意图识别配置
292295
intent_config = self.config["Intent"]
293-
intent_type = self.config["selected_module"]["Intent"]
296+
intent_type = self.config["Intent"][self.config["selected_module"]["Intent"]][
297+
"type"
298+
]
294299

295300
# 如果使用 nointent,直接返回
296301
if intent_type == "nointent":
297302
return
298303
# 使用 intent_llm 模式
299304
elif intent_type == "intent_llm":
300-
intent_llm_name = intent_config["intent_llm"]["llm"]
305+
intent_llm_name = intent_config[self.config["selected_module"]["Intent"]][
306+
"llm"
307+
]
301308

302309
if intent_llm_name and intent_llm_name in self.config["LLM"]:
303310
# 如果配置了专用LLM,则创建独立的LLM实例

main/xiaozhi-server/core/handle/functionHandler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def register_nessary_functions(self):
5757

5858
def register_config_functions(self):
5959
"""注册配置中的函数,可以不同客户端使用不同的配置"""
60-
for func in self.config["Intent"]["function_call"].get("functions", []):
60+
for func in self.config["Intent"][self.config["selected_module"]["Intent"]].get(
61+
"functions", []
62+
):
6163
self.function_registry.register_function(func)
6264

6365
"""home assistant需要初始化提示词"""

main/xiaozhi-server/core/handle/intentHandler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ async def process_intent_result(conn, intent_result, original_text):
7676
if function_name == "continue_chat":
7777
return False
7878

79+
if function_name == "play_music":
80+
funcItem = conn.func_handler.get_function(function_name)
81+
if not funcItem:
82+
conn.func_handler.function_registry.register_function("play_music")
83+
7984
function_args = None
8085
if "arguments" in intent_data["function_call"]:
8186
function_args = intent_data["function_call"]["arguments"]

0 commit comments

Comments
 (0)