Commit f58c7624 authored by alex yao's avatar alex yao

fix: 修复保存variable_structure结构

parent 5019fc74
......@@ -13,7 +13,9 @@ import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem;
import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.expose.dto.SearchAgentApplicationDto;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.tencent.core.utils.JsonUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -50,7 +52,8 @@ public class AgentApplicationInfoConvert {
entity.setPublishTime(model.getPublishTime());
entity.setIsLongMemory(model.getIsLongMemory());
if (StringUtils.isNotBlank(model.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class));
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), new TypeReference<List<Variable>>() {
}.getType()));
}
if (StringUtils.isNotBlank(model.getFeaturedQuestions())) {
entity.setFeaturedQuestions(JsonUtils.deSerialize(model.getFeaturedQuestions(), String[].class));
......@@ -90,7 +93,7 @@ public class AgentApplicationInfoConvert {
model.setPreamble(entity.getPreamble());
model.setPublishTime(entity.getPublishTime());
model.setIsLongMemory(entity.getIsLongMemory());
if (ArrayUtils.isNotEmpty(entity.getVariableStructure())) {
if (CollectionUtils.isNotEmpty(entity.getVariableStructure())) {
model.setVariableStructure(JsonUtils.serialize(entity.getVariableStructure()));
}
if (ArrayUtils.isNotEmpty(entity.getFeaturedQuestions())) {
......@@ -135,24 +138,7 @@ public class AgentApplicationInfoConvert {
commConfig.setContinuousQuestionStatus(entity.getContinuousQuestionStatus());
commConfig.setContinuousQuestionSystem(entity.getContinuousQuestionSystem());
commConfig.setContinuousQuestionTurn(entity.getContinuousQuestionTurn());
List<Variable> variables = new ArrayList<>();
String[] variableStructure = entity.getVariableStructure();
if(variableStructure != null){
for (int i = 0; i < variableStructure.length; i++) {
Variable variable = new Variable();
String input = variableStructure[i];
// 定义正则表达式模式
String regex = "\"key\":\"(.*?)\",\"default\":\"(.*?)\"";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
variable.setKey(matcher.group(1));
variable.setVariableDefault(matcher.group(2));
variables.add(variable);
}
}
}
commConfig.setVariableStructure(variables);
commConfig.setVariableStructure(entity.getVariableStructure());
commConfig.setIsLongMemory(entity.getIsLongMemory());
......@@ -197,15 +183,8 @@ public class AgentApplicationInfoConvert {
entity.setContinuousQuestionStatus(dto.getCommConfig().getContinuousQuestionStatus());
entity.setContinuousQuestionSystem(dto.getCommConfig().getContinuousQuestionSystem());
entity.setContinuousQuestionTurn(dto.getCommConfig().getContinuousQuestionTurn());
if (ObjectUtil.isNotEmpty(dto.getCommConfig().getVariableStructure())) {
List<Variable> variables = dto.getCommConfig().getVariableStructure();
String[] result = new String[variables.size()];
for (int i = 0; i < variables.size(); i++) {
String key = variables.get(i).getKey();
String variableDefault = variables.get(i).getVariableDefault();
result[i] = "\"key\":\"" + key + "\"," + "\"default\":\"" + variableDefault + "\"";
}
entity.setVariableStructure(result);
if (CollectionUtils.isNotEmpty(dto.getCommConfig().getVariableStructure())) {
entity.setVariableStructure(dto.getCommConfig().getVariableStructure());
}
entity.setIsLongMemory(dto.getCommConfig().getIsLongMemory());
}
......@@ -244,7 +223,8 @@ public class AgentApplicationInfoConvert {
entity.setIsLongMemory(infoQueryItem.getIsLongMemory());
if (StringUtils.isNotBlank(infoQueryItem.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(infoQueryItem.getVariableStructure(), String[].class));
entity.setVariableStructure(JsonUtils.deSerialize(infoQueryItem.getVariableStructure(), new TypeReference<List<Variable>>() {
}.getType()));
}
if (StringUtils.isNotBlank(infoQueryItem.getFeaturedQuestions())) {
......
package cn.com.poc.agent_application.convert;
package cn.com.poc.agent_application.convert;
import cn.com.poc.agent_application.domain.AgentApplicationBaseInfo;
import cn.com.poc.agent_application.domain.AgentApplicationCommConfig;
......@@ -21,7 +21,7 @@ import java.util.regex.Pattern;
public class BizAgentApplicationMallConvert {
public static BizAgentApplicationMallEntity modelToEntity(BizAgentApplicationMallModel model){
public static BizAgentApplicationMallEntity modelToEntity(BizAgentApplicationMallModel model) {
BizAgentApplicationMallEntity entity = new BizAgentApplicationMallEntity();
entity.setId(model.getId());
entity.setAgentPublishId(model.getAgentPublishId());
......@@ -34,7 +34,7 @@ public class BizAgentApplicationMallConvert {
return entity;
}
public static BizAgentApplicationMallModel entityToModel(BizAgentApplicationMallEntity entity){
public static BizAgentApplicationMallModel entityToModel(BizAgentApplicationMallEntity entity) {
BizAgentApplicationMallModel model = new BizAgentApplicationMallModel();
model.setId(entity.getId());
model.setAgentPublishId(entity.getAgentPublishId());
......@@ -46,7 +46,7 @@ public class BizAgentApplicationMallConvert {
model.setPopularity(entity.getPopularity());
return model;
}
public static BizAgentApplicationMallDto entityToDto(BizAgentApplicationMallEntity entity) throws Exception {
BizAgentApplicationMallDto dto = new BizAgentApplicationMallDto();
......@@ -55,7 +55,7 @@ public class BizAgentApplicationMallConvert {
BizAgentApplicationPublishEntity publishEntity = agentApplicationPublishService.get(entity.getAgentPublishId());
AgentApplicationBaseInfo baseInfo = new AgentApplicationBaseInfo();
if(publishEntity != null){
if (publishEntity != null) {
baseInfo.setMemberId(publishEntity.getMemberId());
baseInfo.setAgentId(publishEntity.getAgentId());
baseInfo.setAgentTitle(publishEntity.getAgentTitle());
......@@ -67,37 +67,23 @@ public class BizAgentApplicationMallConvert {
}
AgentApplicationCommConfig commConfig = new AgentApplicationCommConfig();
if(publishEntity != null){
if (publishEntity != null) {
commConfig.setPreamble(publishEntity.getPreamble());
commConfig.setFeaturedQuestions(publishEntity.getFeaturedQuestions());
commConfig.setContinuousQuestionStatus(publishEntity.getContinuousQuestionStatus());
commConfig.setContinuousQuestionSystem(publishEntity.getContinuousQuestionSystem());
commConfig.setContinuousQuestionTurn(publishEntity.getContinuousQuestionTurn());
List<Variable> variables = new ArrayList<>();
String[] variableStructure = publishEntity.getVariableStructure();
for (int i = 0; i < variableStructure.length; i++) {
Variable variable = new Variable();
String input = variableStructure[i];
// 定义正则表达式模式
Pattern pattern = Pattern.compile("(key|default):([^,]+)");
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
variable.setKey(matcher.group(1));
variable.setVariableDefault(matcher.group(2));
variables.add(variable);
}
}
commConfig.setVariableStructure(variables);
commConfig.setVariableStructure(publishEntity.getVariableStructure());
commConfig.setIsLongMemory(publishEntity.getIsLongMemory());
}
AgentApplicationKnowledgeConfig knowledgeConfig = new AgentApplicationKnowledgeConfig();
if(publishEntity != null){
if (publishEntity != null) {
knowledgeConfig.setKnowledgeIds(publishEntity.getKnowledgeIds());
}
AgentApplicationCommModelConfig commModelConfig = new AgentApplicationCommModelConfig();
if(publishEntity != null){
if (publishEntity != null) {
commModelConfig.setLargeModel(publishEntity.getLargeModel());
commModelConfig.setTopP(publishEntity.getTopP());
commModelConfig.setCommunicationTurn(publishEntity.getCommunicationTurn());
......@@ -111,7 +97,7 @@ public class BizAgentApplicationMallConvert {
dto.setCommConfig(commConfig);
dto.setKnowledgeConfig(knowledgeConfig);
dto.setCommModelConfig(commModelConfig);
if(publishEntity != null){
if (publishEntity != null) {
dto.setUnitIds(publishEntity.getUnitIds());
}
......@@ -122,7 +108,7 @@ public class BizAgentApplicationMallConvert {
return dto;
}
public static BizAgentApplicationMallEntity dtoToEntity(BizAgentApplicationMallDto dto){
public static BizAgentApplicationMallEntity dtoToEntity(BizAgentApplicationMallDto dto) {
BizAgentApplicationMallEntity entity = new BizAgentApplicationMallEntity();
entity.setId(dto.getId());
entity.setAgentPublishId(dto.getAgentPublishId());
......
......@@ -10,7 +10,9 @@ import cn.com.poc.agent_application.entity.Variable;
import cn.com.poc.agent_application.model.BizAgentApplicationPublishModel;
import cn.com.poc.common.utils.JsonUtils;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import com.tencent.core.utils.JsonUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -34,12 +36,10 @@ public class BizAgentApplicationPublishConvert {
entity.setPreamble(model.getPreamble());
entity.setIsLongMemory(model.getIsLongMemory());
if (StringUtils.isNotBlank(model.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class));
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), new TypeReference<List<Variable>>() {
}.getType()));
}
if (StringUtils.isNotBlank(model.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class));
}
if (StringUtils.isNotBlank(model.getFeaturedQuestions())) {
entity.setFeaturedQuestions(JsonUtils.deSerialize(model.getFeaturedQuestions(), String[].class));
}
......@@ -76,7 +76,7 @@ public class BizAgentApplicationPublishConvert {
model.setAgentSystem(entity.getAgentSystem());
model.setPreamble(entity.getPreamble());
model.setIsLongMemory(entity.getIsLongMemory());
if (ArrayUtils.isNotEmpty(entity.getVariableStructure())) {
if (CollectionUtils.isNotEmpty(entity.getVariableStructure())) {
model.setVariableStructure(JsonUtils.serialize(entity.getVariableStructure()));
}
if (ArrayUtils.isNotEmpty(entity.getFeaturedQuestions())) {
......@@ -122,24 +122,7 @@ public class BizAgentApplicationPublishConvert {
commConfig.setContinuousQuestionStatus(entity.getContinuousQuestionStatus());
commConfig.setContinuousQuestionSystem(entity.getContinuousQuestionSystem());
commConfig.setContinuousQuestionTurn(entity.getContinuousQuestionTurn());
List<Variable> variables = new ArrayList<>();
String[] variableStructure = entity.getVariableStructure();
if(variableStructure != null){
for (int i = 0; i < variableStructure.length; i++) {
Variable variable = new Variable();
String input = variableStructure[i];
// 定义正则表达式模式
String regex = "\"key\":\"(.*?)\",\"default\":\"(.*?)\"";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
if (matcher.find()) {
variable.setKey(matcher.group(1));
variable.setVariableDefault(matcher.group(2));
variables.add(variable);
}
}
}
commConfig.setVariableStructure(variables);
commConfig.setVariableStructure(entity.getVariableStructure());
commConfig.setIsLongMemory(entity.getIsLongMemory());
AgentApplicationKnowledgeConfig knowledgeConfig = new AgentApplicationKnowledgeConfig();
......@@ -184,15 +167,8 @@ public class BizAgentApplicationPublishConvert {
entity.setContinuousQuestionSystem(dto.getCommConfig().getContinuousQuestionSystem());
entity.setContinuousQuestionTurn(dto.getCommConfig().getContinuousQuestionTurn());
entity.setIsLongMemory(dto.getCommConfig().getIsLongMemory());
if (ObjectUtil.isNotEmpty(dto.getCommConfig().getVariableStructure())) {
List<Variable> variables = dto.getCommConfig().getVariableStructure();
String[] result = new String[variables.size()];
for (int i = 0; i < variables.size(); i++) {
String key = variables.get(i).getKey();
String variableDefault = variables.get(i).getVariableDefault();
result[i] = "key:" + key + "," + "default:" + variableDefault;
}
entity.setVariableStructure(result);
if (CollectionUtils.isNotEmpty(dto.getCommConfig().getVariableStructure())) {
entity.setVariableStructure(dto.getCommConfig().getVariableStructure());
}
}
......
......@@ -2,6 +2,7 @@ package cn.com.poc.agent_application.entity;
import javax.persistence.Column;
import java.util.Arrays;
import java.util.List;
public class BizAgentApplicationInfoEntity {
......@@ -290,13 +291,13 @@ public class BizAgentApplicationInfoEntity {
* variable_structure
* 变量结构
*/
private java.lang.String[] variableStructure;
private List<Variable> variableStructure;
public java.lang.String[] getVariableStructure() {
return this.variableStructure;
public List<Variable> getVariableStructure() {
return variableStructure;
}
public void setVariableStructure(java.lang.String[] variableStructure) {
public void setVariableStructure(List<Variable> variableStructure) {
this.variableStructure = variableStructure;
}
......@@ -421,7 +422,7 @@ public class BizAgentApplicationInfoEntity {
", largeModel='" + largeModel + '\'' +
", topP=" + topP +
", unitIds=" + Arrays.toString(unitIds) +
", variableStructure=" + Arrays.toString(variableStructure) +
", variableStructure=" + variableStructure +
", isLongMemory='" + isLongMemory + '\'' +
", isDeleted='" + isDeleted + '\'' +
", creator='" + creator + '\'' +
......
package cn.com.poc.agent_application.entity;
package cn.com.poc.agent_application.entity;
import java.util.List;
public class BizAgentApplicationPublishEntity {
private static final long serialVersionUID = 1L;
......@@ -128,13 +130,13 @@ public class BizAgentApplicationPublishEntity {
/** variable_structure
*变量结构
*/
private java.lang.String[] variableStructure;
private List<Variable> variableStructure;
public java.lang.String[] getVariableStructure(){
public List<Variable> getVariableStructure(){
return this.variableStructure;
}
public void setVariableStructure(java.lang.String[] variableStructure){
public void setVariableStructure(List<Variable> variableStructure){
this.variableStructure = variableStructure;
}
......
......@@ -323,7 +323,7 @@ public class AgentApplicationInfoQueryItem extends BaseItemClass implements Seri
*/
private java.lang.String variableStructure;
@Column(name = "variable_structure", length = 2147483647)
@Column(name = "variable_structure")
public java.lang.String getVariableStructure() {
return this.variableStructure;
}
......
......@@ -72,15 +72,15 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
}
List<BizAgentApplicationInfoEntity> bizAgentApplicationInfoEntities = bizAgentApplicationInfoService.agentApplicationInfoQuery(condition, pagingInfo);
List<AgentApplicationInfoDto> resultList = new ArrayList<>();
for(BizAgentApplicationInfoEntity entity : bizAgentApplicationInfoEntities){
for (BizAgentApplicationInfoEntity entity : bizAgentApplicationInfoEntities) {
AgentApplicationInfoDto infoDto = AgentApplicationInfoConvert.entityToDto(entity);
// 先判断有没有收藏的查询条件
if(StringUtils.isNotBlank(dto.getIsCollect())){
if (StringUtils.isNotBlank(dto.getIsCollect())) {
// 如果有查询条件,则判断符不符合条件
if(infoDto.getBaseInfo() != null){
if (infoDto.getBaseInfo() != null) {
BizMemberAgentApplicationCollectEntity collect = bizMemberAgentApplicationCollectService.getByAgentId(infoDto.getBaseInfo().getAgentId());
// 如果符合条件,则把值加入
if(collect != null && collect.getIsCollect().equals(dto.getIsCollect())){
if (collect != null && collect.getIsCollect().equals(dto.getIsCollect())) {
infoDto.setIsCollect(collect.getIsCollect());
} else if ((collect == null && CommonConstant.IsDeleted.N.equals(dto.getIsCollect()))) {
infoDto.setIsCollect(CommonConstant.IsDeleted.N);
......@@ -88,33 +88,33 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
// 如果不符合条件,则continue
continue;
}
}else {
} else {
continue;
}
}else {
} else {
// 如何没有查询条件,则直接按照原来的逻辑走
// 设置当前用户是否收藏了
if(infoDto.getBaseInfo() != null){
if (infoDto.getBaseInfo() != null) {
BizMemberAgentApplicationCollectEntity collect = bizMemberAgentApplicationCollectService.getByAgentId(infoDto.getBaseInfo().getAgentId());
if(collect != null){
if (collect != null) {
infoDto.setIsCollect(collect.getIsCollect());
}else {
} else {
infoDto.setIsCollect(CommonConstant.IsDeleted.N);
}
}
}
// 判断是否发布了,若发布则设置agentPublishId
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(entity.getAgentId());
if(publishEntity != null){
if (publishEntity != null) {
infoDto.setAgentPublishId(publishEntity.getId());
// 设置当前作品是否上架
BizAgentApplicationMallEntity mallEntity = bizAgentApplicationMallService.getByAgentPublishId(publishEntity.getId());
if(mallEntity != null){
if (mallEntity != null) {
infoDto.setIsSale(mallEntity.getIsSale());
}else{
} else {
infoDto.setIsSale(CommonConstant.IsDeleted.N);
}
}else{
} else {
infoDto.setAgentPublishId(null);
}
resultList.add(infoDto);
......@@ -165,7 +165,7 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
bizAgentApplicationInfoService.deletedByAgentId(agentId);
// 删除应用
BizAgentApplicationPublishEntity publishEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if(publishEntity != null){
if (publishEntity != null) {
// 删除应用市场表中的应用
bizAgentApplicationMallService.deletedByAgentPublishId(publishEntity.getId());
// 删除发布表中的应用
......@@ -204,11 +204,12 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
//配置对话function
List<Tool> tools = new ArrayList<>();
//开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
if (CollectionUtils.isNotEmpty(infoEntity.getVariableStructure())) {
//todo 修正
String functionName = LargeModelFunctionEnum.set_value_memory.name();
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
// String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
// Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
// tools.add(tool);
}
//开启长期记忆
if (CommonConstant.YOrN.Y.equals(infoEntity.getIsLongMemory())) {
......
......@@ -310,11 +310,11 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
private List<Tool> buildMemoryConfig(BizAgentApplicationPublishEntity infoEntity) {
List<Tool> tools = new ArrayList<>();
//开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
String functionName = LargeModelFunctionEnum.set_value_memory.name();
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
if (CollectionUtils.isNotEmpty(infoEntity.getVariableStructure())) {
// String functionName = LargeModelFunctionEnum.set_value_memory.name();
// String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getVariableStructureLLMConfig(infoEntity.getVariableStructure()).get(0);
// Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
// tools.add(tool);
}
//开启长期记忆
if (CommonConstant.YOrN.Y.equals(infoEntity.getIsLongMemory())) {
......
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.agent_application.entity.Variable;
import java.util.List;
public abstract class AbstractLargeModelFunction {
......@@ -15,6 +17,6 @@ public abstract class AbstractLargeModelFunction {
/**
* 获取有关变量的配置
*/
public abstract List<String> getVariableStructureLLMConfig(String[] variableStructure);
public abstract List<String> getVariableStructureLLMConfig(List<Variable> variableStructure);
}
package cn.com.poc.thirdparty.resource.demand.ai.function.long_memory;
import cn.com.poc.agent_application.entity.Variable;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.DateUtils;
......@@ -82,7 +83,7 @@ public class SetLongMemoryFunction extends AbstractLargeModelFunction {
}
@Override
public List<String> getVariableStructureLLMConfig(String[] variableStructure) {
public List<String> getVariableStructureLLMConfig(List<Variable> variableStructure) {
throw new BusinessException("暂不支持变量结构配置");
}
}
package cn.com.poc.thirdparty.resource.demand.ai.function.value_memory;
import cn.com.poc.agent_application.entity.Variable;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.thirdparty.resource.demand.ai.function.AbstractLargeModelFunction;
......@@ -49,7 +50,7 @@ public class SetValueMemoryFunction extends AbstractLargeModelFunction {
}
@Override
public List<String> getVariableStructureLLMConfig(String[] variableStructure) {
public List<String> getVariableStructureLLMConfig(List<Variable> variableStructure) {
Map<String, Object> config = new HashMap<>();
Map<String, Object> function = new HashMap<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment