diff --git a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java index f07b7c14..96a4d014 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/agent/service/impl/AgentServiceImpl.java @@ -327,7 +327,7 @@ public class AgentServiceImpl extends BaseServiceImpl imp } boolean b = validateLLMIntentParams(dto.getLlmModelId(), dto.getIntentModelId()); - if(!b){ + if (!b) { throw new RenException("LLM大模型和Intent意图识别,选择参数不匹配"); } this.updateById(existingEntity); @@ -335,19 +335,20 @@ public class AgentServiceImpl extends BaseServiceImpl imp /** * 验证大语言模型和意图识别的参数是否符合匹配 - * @param llmModelId 大语言模型id + * + * @param llmModelId 大语言模型id * @param intentModelId 意图识别id * @return T 匹配 : F 不匹配 */ - private boolean validateLLMIntentParams(String llmModelId,String intentModelId){ + private boolean validateLLMIntentParams(String llmModelId, String intentModelId) { ModelConfigEntity llmModelData = modelConfigService.selectById(llmModelId); String type = llmModelData.getConfigJson().get("type").toString(); // 如果查询大语言模型是openai或者ollama,意图识别选参数都可以 - if("openai".equals(type) || "ollama".equals(type)){ + if ("openai".equals(type) || "ollama".equals(type)) { return true; } - // 除了openai和ollama的类型,不可以选择id为Intent_nointent(无意图识别)的意图识别 - return !"Intent_nointent".equals(intentModelId); + // 除了openai和ollama的类型,不可以选择id为Intent_function_call(函数调用)的意图识别 + return !"Intent_function_call".equals(intentModelId); } @Override diff --git a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java index c0931277..c156b408 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/model/service/impl/ModelConfigServiceImpl.java @@ -5,10 +5,10 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -24,7 +24,11 @@ import xiaozhi.common.utils.ConvertUtils; import xiaozhi.modules.agent.dao.AgentDao; import xiaozhi.modules.agent.entity.AgentEntity; import xiaozhi.modules.model.dao.ModelConfigDao; -import xiaozhi.modules.model.dto.*; +import xiaozhi.modules.model.dto.LlmModelBasicInfoDTO; +import xiaozhi.modules.model.dto.ModelBasicInfoDTO; +import xiaozhi.modules.model.dto.ModelConfigBodyDTO; +import xiaozhi.modules.model.dto.ModelConfigDTO; +import xiaozhi.modules.model.dto.ModelProviderDTO; import xiaozhi.modules.model.entity.ModelConfigEntity; import xiaozhi.modules.model.service.ModelConfigService; import xiaozhi.modules.model.service.ModelProviderService; @@ -49,6 +53,7 @@ public class ModelConfigServiceImpl extends BaseServiceImpl getLlmModelCodeList(String modelName) { List entities = modelConfigDao.selectList( @@ -56,7 +61,7 @@ public class ModelConfigServiceImpl extends BaseServiceImpl { LlmModelBasicInfoDTO dto = new LlmModelBasicInfoDTO(); @@ -68,7 +73,6 @@ public class ModelConfigServiceImpl extends BaseServiceImpl getPageList(String modelType, String modelName, String page, String limit) { Map params = new HashMap(); @@ -111,16 +115,18 @@ public class ModelConfigServiceImpl extends BaseServiceImpl() .eq(ModelConfigEntity::getId, llm)); - if(modelConfigEntity == null){ + String selectModelType = (modelConfigEntity == null || modelConfigEntity.getModelType() == null) ? null + : modelConfigEntity.getModelType().toUpperCase(); + if (modelConfigEntity == null || !"LLM".equals(selectModelType)) { throw new RenException("设置的LLM不存在"); } String type = modelConfigEntity.getConfigJson().get("type").toString(); // 如果查询大语言模型是openai或者ollama,意图识别选参数都可以 - if(!"openai".equals(type) && !"ollama".equals(type)){ + if (!"openai".equals(type) && !"ollama".equals(type)) { throw new RenException("设置的LLM不是openai和ollama"); } } diff --git a/main/manager-web/src/views/roleConfig.vue b/main/manager-web/src/views/roleConfig.vue index ff9ac6d2..bbba01bd 100644 --- a/main/manager-web/src/views/roleConfig.vue +++ b/main/manager-web/src/views/roleConfig.vue @@ -356,6 +356,9 @@ export default { }); // 备份原始,以备取消时恢复 this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions)); + + // 确保意图识别选项的可见性正确 + this.updateIntentOptionsVisibility(); }); } else { this.$message.error(data.msg || '获取配置失败'); @@ -372,6 +375,11 @@ export default { label: item.modelName, isHidden: false }))); + + // 如果是意图识别选项,需要根据当前LLM类型更新可见性 + if (model.type === 'Intent') { + this.updateIntentOptionsVisibility(); + } } else { this.$message.error(data.msg || '获取模型列表失败'); } @@ -431,22 +439,8 @@ export default { this.form.chatHistoryConf = 2; } if (type === 'LLM') { - let llmType = this.llmModeTypeMap.get(value) - let memory - for (let item of this.modelOptions['Intent']) { - if(item.value == "Intent_nointent" ) { - memory = item - break - } - } - if (llmType == "openai" || llmType == "ollama") { - memory.isHidden = false - }else{ - memory.isHidden = true - } - if(this.form.model.intentModelId == "Intent_nointent"){ - this.form.model.intentModelId = ''; - } + // 当LLM类型改变时,更新意图识别选项的可见性 + this.updateIntentOptionsVisibility(); } }, fetchAllFunctions() { @@ -488,6 +482,42 @@ export default { } this.showFunctionDialog = false; }, + updateIntentOptionsVisibility() { + // 根据当前选择的LLM类型更新意图识别选项的可见性 + const currentLlmId = this.form.model.llmModelId; + if (!currentLlmId || !this.modelOptions['Intent']) return; + + const llmType = this.llmModeTypeMap.get(currentLlmId); + if (!llmType) return; + + this.modelOptions['Intent'].forEach(item => { + if (item.value === "Intent_function_call") { + // 如果llmType是openai或ollama,允许选择function_call + // 否则隐藏function_call选项 + if (llmType === "openai" || llmType === "ollama") { + item.isHidden = false; + } else { + item.isHidden = true; + } + } else { + // 其他意图识别选项始终可见 + item.isHidden = false; + } + }); + + // 如果当前选择的意图识别是function_call,但LLM类型不支持,则设置为可选的第一项 + if (this.form.model.intentModelId === "Intent_function_call" && + llmType !== "openai" && llmType !== "ollama") { + // 找到第一个可见的选项 + const firstVisibleOption = this.modelOptions['Intent'].find(item => !item.isHidden); + if (firstVisibleOption) { + this.form.model.intentModelId = firstVisibleOption.value; + } else { + // 如果没有可见选项,设置为Intent_nointent + this.form.model.intentModelId = 'Intent_nointent'; + } + } + }, updateChatHistoryConf() { if (this.form.model.memModelId === 'Memory_nomem') { this.form.chatHistoryConf = 0;