diff --git a/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java index a139289d9..78a7b5114 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/config/service/impl/ConfigServiceImpl.java @@ -231,8 +231,9 @@ public class ConfigServiceImpl implements ConfigService { boolean isCache) { Map selectedModule = new HashMap<>(); - String[] modelTypes = { "VAD", "ASR", "LLM", "TTS", "Memory", "Intent" }; - String[] modelIds = { vadModelId, asrModelId, llmModelId, ttsModelId, memModelId, intentModelId }; + String[] modelTypes = { "VAD", "ASR", "TTS", "Memory", "Intent", "LLM" }; + String[] modelIds = { vadModelId, asrModelId, ttsModelId, memModelId, intentModelId, llmModelId }; + String intentLLMModelId = null; for (int i = 0; i < modelIds.length; i++) { if (modelIds[i] == null) { @@ -246,10 +247,27 @@ public class ConfigServiceImpl implements ConfigService { if ("TTS".equals(modelTypes[i]) && voice != null) { ((Map) model.getConfigJson()).put("private_voice", voice); } + // 如果是Intent类型,且type=intent_llm,则给他添加附加模型 + if ("Intent".equals(modelTypes[i])) { + Map map = (Map) 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); + selectedModule.put(modelTypes[i], model.getId()); } + result.put("selected_module", selectedModule); if (StringUtils.isNotBlank(prompt)) { prompt = prompt.replace("{{assistant_name}}", "小智"); diff --git a/main/manager-api/src/main/resources/db/changelog/202504131541.sql b/main/manager-api/src/main/resources/db/changelog/202504131541.sql deleted file mode 100644 index 7e88fde94..000000000 --- a/main/manager-api/src/main/resources/db/changelog/202504131541.sql +++ /dev/null @@ -1,2 +0,0 @@ --- 对0.3.0版本之前的参数进行修改 -update `sys_params` set param_value = '.mp3;.wav;.p3' where param_code = 'plugins.play_music.music_ext'; \ No newline at end of file diff --git a/main/manager-api/src/main/resources/db/changelog/202504131542.sql b/main/manager-api/src/main/resources/db/changelog/202504131542.sql new file mode 100644 index 000000000..383ba1873 --- /dev/null +++ b/main/manager-api/src/main/resources/db/changelog/202504131542.sql @@ -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'; diff --git a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml index bf533db1c..41f65488b 100755 --- a/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml +++ b/main/manager-api/src/main/resources/db/changelog/db.changelog-master.yaml @@ -52,9 +52,9 @@ databaseChangeLog: encoding: utf8 path: classpath:db/changelog/202504112058.sql - changeSet: - id: 202504131541 + id: 202504131542 author: John changes: - sqlFile: encoding: utf8 - path: classpath:db/changelog/202504131541.sql \ No newline at end of file + path: classpath:db/changelog/202504131542.sql \ No newline at end of file diff --git a/main/xiaozhi-server/core/providers/llm/openai/openai.py b/main/xiaozhi-server/core/providers/llm/openai/openai.py index 9a9748ca5..d6e66dcfc 100644 --- a/main/xiaozhi-server/core/providers/llm/openai/openai.py +++ b/main/xiaozhi-server/core/providers/llm/openai/openai.py @@ -15,7 +15,15 @@ class LLMProvider(LLMProviderBase): self.base_url = config.get("base_url") else: 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) self.client = openai.OpenAI(api_key=self.api_key, base_url=self.base_url) diff --git a/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py b/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py index e4769d00e..affa8af2f 100644 --- a/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py +++ b/main/xiaozhi-server/plugins_func/functions/handle_exit_intent.py @@ -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 TAG = __name__ logger = setup_logging() handle_exit_intent_function_desc = { - "type": "function", - "function": { - "name": "handle_exit_intent", - "description": "当用户想结束对话或需要退出系统时调用", - "parameters": { - "type": "object", - "properties": { - "say_goodbye": { - "type": "string", - "description": "和用户友好结束对话的告别语" - } - }, - "required": ["say_goodbye"] - } + "type": "function", + "function": { + "name": "handle_exit_intent", + "description": "当用户想结束对话或需要退出系统时调用", + "parameters": { + "type": "object", + "properties": { + "say_goodbye": { + "type": "string", + "description": "和用户友好结束对话的告别语", } - } + }, + "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: + if say_goodbye is None: + say_goodbye = "再见,祝您生活愉快!" conn.close_after_chat = True 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: logger.bind(tag=TAG).error(f"处理退出意图错误: {e}") - return ActionResponse(action=Action.NONE, result="退出意图处理失败", response="") \ No newline at end of file + return ActionResponse( + action=Action.NONE, result="退出意图处理失败", response="" + )