mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
fix:manager第一图识别使用独立llm无法初始化llm的bug
This commit is contained in:
parent
bfb4b74dbd
commit
7782a5af7a
6 changed files with 63 additions and 27 deletions
|
|
@ -231,8 +231,9 @@ public class ConfigServiceImpl implements ConfigService {
|
||||||
boolean isCache) {
|
boolean isCache) {
|
||||||
Map<String, String> selectedModule = new HashMap<>();
|
Map<String, String> selectedModule = new HashMap<>();
|
||||||
|
|
||||||
String[] modelTypes = { "VAD", "ASR", "LLM", "TTS", "Memory", "Intent" };
|
String[] modelTypes = { "VAD", "ASR", "TTS", "Memory", "Intent", "LLM" };
|
||||||
String[] modelIds = { vadModelId, asrModelId, llmModelId, ttsModelId, memModelId, intentModelId };
|
String[] modelIds = { vadModelId, asrModelId, ttsModelId, memModelId, intentModelId, llmModelId };
|
||||||
|
String intentLLMModelId = null;
|
||||||
|
|
||||||
for (int i = 0; i < modelIds.length; i++) {
|
for (int i = 0; i < modelIds.length; i++) {
|
||||||
if (modelIds[i] == null) {
|
if (modelIds[i] == null) {
|
||||||
|
|
@ -246,10 +247,27 @@ public class ConfigServiceImpl implements ConfigService {
|
||||||
if ("TTS".equals(modelTypes[i]) && voice != null) {
|
if ("TTS".equals(modelTypes[i]) && voice != null) {
|
||||||
((Map<String, Object>) model.getConfigJson()).put("private_voice", voice);
|
((Map<String, Object>) model.getConfigJson()).put("private_voice", voice);
|
||||||
}
|
}
|
||||||
|
// 如果是Intent类型,且type=intent_llm,则给他添加附加模型
|
||||||
|
if ("Intent".equals(modelTypes[i])) {
|
||||||
|
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
||||||
|
if ("intent_llm".equals(map.get("type"))) {
|
||||||
|
intentLLMModelId = (String) map.get("llm");
|
||||||
|
if (intentLLMModelId != null && intentLLMModelId.equals(llmModelId)) {
|
||||||
|
intentLLMModelId = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果是LLM类型,且intentLLMModelId不为空,则添加附加模型
|
||||||
|
if ("LLM".equals(modelTypes[i]) && intentLLMModelId != null) {
|
||||||
|
ModelConfigEntity intentLLM = modelConfigService.getModelById(intentLLMModelId, isCache);
|
||||||
|
typeConfig.put(intentLLM.getId(), intentLLM.getConfigJson());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result.put(modelTypes[i], typeConfig);
|
result.put(modelTypes[i], typeConfig);
|
||||||
|
|
||||||
selectedModule.put(modelTypes[i], model.getId());
|
selectedModule.put(modelTypes[i], model.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put("selected_module", selectedModule);
|
result.put("selected_module", selectedModule);
|
||||||
if (StringUtils.isNotBlank(prompt)) {
|
if (StringUtils.isNotBlank(prompt)) {
|
||||||
prompt = prompt.replace("{{assistant_name}}", "小智");
|
prompt = prompt.replace("{{assistant_name}}", "小智");
|
||||||
|
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
-- 对0.3.0版本之前的参数进行修改
|
|
||||||
update `sys_params` set param_value = '.mp3;.wav;.p3' where param_code = 'plugins.play_music.music_ext';
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
-- 对0.3.0版本之前的参数进行修改
|
||||||
|
update `sys_params` set param_value = '.mp3;.wav;.p3' where param_code = 'plugins.play_music.music_ext';
|
||||||
|
update `ai_model_config` set config_json = '{\"type\": \"intent_llm\", \"llm\": \"LLM_ChatGLMLLM\"}' where id = 'Intent_intent_llm';
|
||||||
|
|
@ -52,9 +52,9 @@ databaseChangeLog:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202504112058.sql
|
path: classpath:db/changelog/202504112058.sql
|
||||||
- changeSet:
|
- changeSet:
|
||||||
id: 202504131541
|
id: 202504131542
|
||||||
author: John
|
author: John
|
||||||
changes:
|
changes:
|
||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202504131541.sql
|
path: classpath:db/changelog/202504131542.sql
|
||||||
|
|
@ -15,7 +15,15 @@ class LLMProvider(LLMProviderBase):
|
||||||
self.base_url = config.get("base_url")
|
self.base_url = config.get("base_url")
|
||||||
else:
|
else:
|
||||||
self.base_url = config.get("url")
|
self.base_url = config.get("url")
|
||||||
self.max_tokens = config.get("max_tokens", 500)
|
max_tokens = config.get("max_tokens")
|
||||||
|
if max_tokens is None or max_tokens == "":
|
||||||
|
max_tokens = 500
|
||||||
|
|
||||||
|
try:
|
||||||
|
max_tokens = int(max_tokens)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
max_tokens = 500
|
||||||
|
self.max_tokens = max_tokens
|
||||||
|
|
||||||
check_model_key("LLM", self.api_key)
|
check_model_key("LLM", self.api_key)
|
||||||
self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url)
|
self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url)
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,43 @@
|
||||||
from plugins_func.register import register_function,ToolType, ActionResponse, Action
|
from plugins_func.register import register_function, ToolType, ActionResponse, Action
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
|
|
||||||
handle_exit_intent_function_desc = {
|
handle_exit_intent_function_desc = {
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {
|
||||||
"name": "handle_exit_intent",
|
"name": "handle_exit_intent",
|
||||||
"description": "当用户想结束对话或需要退出系统时调用",
|
"description": "当用户想结束对话或需要退出系统时调用",
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"say_goodbye": {
|
"say_goodbye": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "和用户友好结束对话的告别语"
|
"description": "和用户友好结束对话的告别语",
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": ["say_goodbye"]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"required": ["say_goodbye"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
@register_function('handle_exit_intent', handle_exit_intent_function_desc, ToolType.SYSTEM_CTL)
|
|
||||||
def handle_exit_intent(conn, say_goodbye: str):
|
@register_function(
|
||||||
|
"handle_exit_intent", handle_exit_intent_function_desc, ToolType.SYSTEM_CTL
|
||||||
|
)
|
||||||
|
def handle_exit_intent(conn, say_goodbye: str | None = None):
|
||||||
# 处理退出意图
|
# 处理退出意图
|
||||||
try:
|
try:
|
||||||
|
if say_goodbye is None:
|
||||||
|
say_goodbye = "再见,祝您生活愉快!"
|
||||||
conn.close_after_chat = True
|
conn.close_after_chat = True
|
||||||
logger.bind(tag=TAG).info(f"退出意图已处理:{say_goodbye}")
|
logger.bind(tag=TAG).info(f"退出意图已处理:{say_goodbye}")
|
||||||
return ActionResponse(action=Action.RESPONSE, result="退出意图已处理", response=say_goodbye)
|
return ActionResponse(
|
||||||
|
action=Action.RESPONSE, result="退出意图已处理", response=say_goodbye
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"处理退出意图错误: {e}")
|
logger.bind(tag=TAG).error(f"处理退出意图错误: {e}")
|
||||||
return ActionResponse(action=Action.NONE, result="退出意图处理失败", response="")
|
return ActionResponse(
|
||||||
|
action=Action.NONE, result="退出意图处理失败", response=""
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue