mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
update:优化逻辑
This commit is contained in:
+7
-6
@@ -327,7 +327,7 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean b = validateLLMIntentParams(dto.getLlmModelId(), dto.getIntentModelId());
|
boolean b = validateLLMIntentParams(dto.getLlmModelId(), dto.getIntentModelId());
|
||||||
if(!b){
|
if (!b) {
|
||||||
throw new RenException("LLM大模型和Intent意图识别,选择参数不匹配");
|
throw new RenException("LLM大模型和Intent意图识别,选择参数不匹配");
|
||||||
}
|
}
|
||||||
this.updateById(existingEntity);
|
this.updateById(existingEntity);
|
||||||
@@ -335,19 +335,20 @@ public class AgentServiceImpl extends BaseServiceImpl<AgentDao, AgentEntity> imp
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证大语言模型和意图识别的参数是否符合匹配
|
* 验证大语言模型和意图识别的参数是否符合匹配
|
||||||
* @param llmModelId 大语言模型id
|
*
|
||||||
|
* @param llmModelId 大语言模型id
|
||||||
* @param intentModelId 意图识别id
|
* @param intentModelId 意图识别id
|
||||||
* @return T 匹配 : F 不匹配
|
* @return T 匹配 : F 不匹配
|
||||||
*/
|
*/
|
||||||
private boolean validateLLMIntentParams(String llmModelId,String intentModelId){
|
private boolean validateLLMIntentParams(String llmModelId, String intentModelId) {
|
||||||
ModelConfigEntity llmModelData = modelConfigService.selectById(llmModelId);
|
ModelConfigEntity llmModelData = modelConfigService.selectById(llmModelId);
|
||||||
String type = llmModelData.getConfigJson().get("type").toString();
|
String type = llmModelData.getConfigJson().get("type").toString();
|
||||||
// 如果查询大语言模型是openai或者ollama,意图识别选参数都可以
|
// 如果查询大语言模型是openai或者ollama,意图识别选参数都可以
|
||||||
if("openai".equals(type) || "ollama".equals(type)){
|
if ("openai".equals(type) || "ollama".equals(type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// 除了openai和ollama的类型,不可以选择id为Intent_nointent(无意图识别)的意图识别
|
// 除了openai和ollama的类型,不可以选择id为Intent_function_call(函数调用)的意图识别
|
||||||
return !"Intent_nointent".equals(intentModelId);
|
return !"Intent_function_call".equals(intentModelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+13
-7
@@ -5,10 +5,10 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
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.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
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.dao.AgentDao;
|
||||||
import xiaozhi.modules.agent.entity.AgentEntity;
|
import xiaozhi.modules.agent.entity.AgentEntity;
|
||||||
import xiaozhi.modules.model.dao.ModelConfigDao;
|
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.entity.ModelConfigEntity;
|
||||||
import xiaozhi.modules.model.service.ModelConfigService;
|
import xiaozhi.modules.model.service.ModelConfigService;
|
||||||
import xiaozhi.modules.model.service.ModelProviderService;
|
import xiaozhi.modules.model.service.ModelProviderService;
|
||||||
@@ -49,6 +53,7 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
|
|||||||
.select("id", "model_name"));
|
.select("id", "model_name"));
|
||||||
return ConvertUtils.sourceToTarget(entities, ModelBasicInfoDTO.class);
|
return ConvertUtils.sourceToTarget(entities, ModelBasicInfoDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<LlmModelBasicInfoDTO> getLlmModelCodeList(String modelName) {
|
public List<LlmModelBasicInfoDTO> getLlmModelCodeList(String modelName) {
|
||||||
List<ModelConfigEntity> entities = modelConfigDao.selectList(
|
List<ModelConfigEntity> entities = modelConfigDao.selectList(
|
||||||
@@ -56,7 +61,7 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
|
|||||||
.eq("model_type", "llm")
|
.eq("model_type", "llm")
|
||||||
.eq("is_enabled", 1)
|
.eq("is_enabled", 1)
|
||||||
.like(StringUtils.isNotBlank(modelName), "model_name", "%" + modelName + "%")
|
.like(StringUtils.isNotBlank(modelName), "model_name", "%" + modelName + "%")
|
||||||
.select("id", "model_name","config_json"));
|
.select("id", "model_name", "config_json"));
|
||||||
// 处理获取到的内容
|
// 处理获取到的内容
|
||||||
return entities.stream().map(item -> {
|
return entities.stream().map(item -> {
|
||||||
LlmModelBasicInfoDTO dto = new LlmModelBasicInfoDTO();
|
LlmModelBasicInfoDTO dto = new LlmModelBasicInfoDTO();
|
||||||
@@ -68,7 +73,6 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<ModelConfigDTO> getPageList(String modelType, String modelName, String page, String limit) {
|
public PageData<ModelConfigDTO> getPageList(String modelType, String modelName, String page, String limit) {
|
||||||
Map<String, Object> params = new HashMap<String, Object>();
|
Map<String, Object> params = new HashMap<String, Object>();
|
||||||
@@ -111,16 +115,18 @@ public class ModelConfigServiceImpl extends BaseServiceImpl<ModelConfigDao, Mode
|
|||||||
if (CollectionUtil.isEmpty(providerList)) {
|
if (CollectionUtil.isEmpty(providerList)) {
|
||||||
throw new RenException("供应器不存在");
|
throw new RenException("供应器不存在");
|
||||||
}
|
}
|
||||||
if(modelConfigBodyDTO.getConfigJson().containsKey("llm")){
|
if (modelConfigBodyDTO.getConfigJson().containsKey("llm")) {
|
||||||
String llm = modelConfigBodyDTO.getConfigJson().get("llm").toString();
|
String llm = modelConfigBodyDTO.getConfigJson().get("llm").toString();
|
||||||
ModelConfigEntity modelConfigEntity = modelConfigDao.selectOne(new LambdaQueryWrapper<ModelConfigEntity>()
|
ModelConfigEntity modelConfigEntity = modelConfigDao.selectOne(new LambdaQueryWrapper<ModelConfigEntity>()
|
||||||
.eq(ModelConfigEntity::getId, llm));
|
.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不存在");
|
throw new RenException("设置的LLM不存在");
|
||||||
}
|
}
|
||||||
String type = modelConfigEntity.getConfigJson().get("type").toString();
|
String type = modelConfigEntity.getConfigJson().get("type").toString();
|
||||||
// 如果查询大语言模型是openai或者ollama,意图识别选参数都可以
|
// 如果查询大语言模型是openai或者ollama,意图识别选参数都可以
|
||||||
if(!"openai".equals(type) && !"ollama".equals(type)){
|
if (!"openai".equals(type) && !"ollama".equals(type)) {
|
||||||
throw new RenException("设置的LLM不是openai和ollama");
|
throw new RenException("设置的LLM不是openai和ollama");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -356,6 +356,9 @@ export default {
|
|||||||
});
|
});
|
||||||
// 备份原始,以备取消时恢复
|
// 备份原始,以备取消时恢复
|
||||||
this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions));
|
this.originalFunctions = JSON.parse(JSON.stringify(this.currentFunctions));
|
||||||
|
|
||||||
|
// 确保意图识别选项的可见性正确
|
||||||
|
this.updateIntentOptionsVisibility();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(data.msg || '获取配置失败');
|
this.$message.error(data.msg || '获取配置失败');
|
||||||
@@ -372,6 +375,11 @@ export default {
|
|||||||
label: item.modelName,
|
label: item.modelName,
|
||||||
isHidden: false
|
isHidden: false
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
// 如果是意图识别选项,需要根据当前LLM类型更新可见性
|
||||||
|
if (model.type === 'Intent') {
|
||||||
|
this.updateIntentOptionsVisibility();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(data.msg || '获取模型列表失败');
|
this.$message.error(data.msg || '获取模型列表失败');
|
||||||
}
|
}
|
||||||
@@ -431,22 +439,8 @@ export default {
|
|||||||
this.form.chatHistoryConf = 2;
|
this.form.chatHistoryConf = 2;
|
||||||
}
|
}
|
||||||
if (type === 'LLM') {
|
if (type === 'LLM') {
|
||||||
let llmType = this.llmModeTypeMap.get(value)
|
// 当LLM类型改变时,更新意图识别选项的可见性
|
||||||
let memory
|
this.updateIntentOptionsVisibility();
|
||||||
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 = '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchAllFunctions() {
|
fetchAllFunctions() {
|
||||||
@@ -488,6 +482,42 @@ export default {
|
|||||||
}
|
}
|
||||||
this.showFunctionDialog = false;
|
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() {
|
updateChatHistoryConf() {
|
||||||
if (this.form.model.memModelId === 'Memory_nomem') {
|
if (this.form.model.memModelId === 'Memory_nomem') {
|
||||||
this.form.chatHistoryConf = 0;
|
this.form.chatHistoryConf = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user