Commit 6749f753 authored by alex yao's avatar alex yao

Merge branch 'task/temp_function_call' into 'release'

Task/temp function call

See merge request !3
parents a3f0e6c8 fc5cac7c
...@@ -3,6 +3,7 @@ package cn.com.poc.agent_application.aggregate; ...@@ -3,6 +3,7 @@ package cn.com.poc.agent_application.aggregate;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.entity.CreateAgentTitleAndDescEntity; import cn.com.poc.agent_application.entity.CreateAgentTitleAndDescEntity;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Tool;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
...@@ -17,9 +18,9 @@ public interface AgentApplicationInfoService { ...@@ -17,9 +18,9 @@ public interface AgentApplicationInfoService {
/** /**
* 应用预览 * 应用预览
*/ */
String callAgentApplication(String largeModel, String[] unitIds, String agentSystem, String callAgentApplication(String identifier, String largeModel, String[] unitIds, String agentSystem,
Integer[] kdIds, Integer communicationTurn, Float topP, Integer[] knowledgeIds, Integer communicationTurn, Float topP,
List<Message> messages, HttpServletResponse httpServletResponse) throws Exception; List<Message> messages, List<Tool> tools, HttpServletResponse httpServletResponse) throws Exception;
/** /**
......
...@@ -2,6 +2,16 @@ package cn.com.poc.agent_application.constant; ...@@ -2,6 +2,16 @@ package cn.com.poc.agent_application.constant;
public interface AgentApplicationConstants { public interface AgentApplicationConstants {
interface USE_AGENT_STATUS {
String PREVIEW = "preview";
String PUBLISH = "publish";
}
interface TOOLS {
int FUNCTION_NUMBER = 4;
}
interface AGENT_PUBLISH_STATUS { interface AGENT_PUBLISH_STATUS {
String DRAFT = "draft"; // 草稿 String DRAFT = "draft"; // 草稿
......
...@@ -4,9 +4,9 @@ import cn.com.poc.agent_application.domain.AgentApplicationBaseInfo; ...@@ -4,9 +4,9 @@ import cn.com.poc.agent_application.domain.AgentApplicationBaseInfo;
import cn.com.poc.agent_application.domain.AgentApplicationCommConfig; import cn.com.poc.agent_application.domain.AgentApplicationCommConfig;
import cn.com.poc.agent_application.domain.AgentApplicationCommModelConfig; import cn.com.poc.agent_application.domain.AgentApplicationCommModelConfig;
import cn.com.poc.agent_application.domain.AgentApplicationKnowledgeConfig; import cn.com.poc.agent_application.domain.AgentApplicationKnowledgeConfig;
import cn.com.poc.agent_application.model.BizAgentApplicationInfoModel;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto; import cn.com.poc.agent_application.dto.AgentApplicationInfoDto;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.model.BizAgentApplicationInfoModel;
import cn.com.poc.agent_application.query.AgentApplicationInfoQueryItem; import cn.com.poc.agent_application.query.AgentApplicationInfoQueryItem;
import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem; import cn.com.poc.agent_application.query.PublishAgentApplicationQueryItem;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
...@@ -42,6 +42,7 @@ public class AgentApplicationInfoConvert { ...@@ -42,6 +42,7 @@ public class AgentApplicationInfoConvert {
entity.setAgentPublishStatus(model.getAgentPublishStatus()); entity.setAgentPublishStatus(model.getAgentPublishStatus());
entity.setPreamble(model.getPreamble()); entity.setPreamble(model.getPreamble());
entity.setPublishTime(model.getPublishTime()); entity.setPublishTime(model.getPublishTime());
entity.setIsLongMemory(model.getIsLongMemory());
if (StringUtils.isNotBlank(model.getVariableStructure())) { if (StringUtils.isNotBlank(model.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class)); entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class));
} }
...@@ -81,6 +82,7 @@ public class AgentApplicationInfoConvert { ...@@ -81,6 +82,7 @@ public class AgentApplicationInfoConvert {
model.setAgentPublishStatus(entity.getAgentPublishStatus()); model.setAgentPublishStatus(entity.getAgentPublishStatus());
model.setPreamble(entity.getPreamble()); model.setPreamble(entity.getPreamble());
model.setPublishTime(entity.getPublishTime()); model.setPublishTime(entity.getPublishTime());
model.setIsLongMemory(entity.getIsLongMemory());
if (ArrayUtils.isNotEmpty(entity.getVariableStructure())) { if (ArrayUtils.isNotEmpty(entity.getVariableStructure())) {
model.setVariableStructure(JsonUtils.serialize(entity.getVariableStructure())); model.setVariableStructure(JsonUtils.serialize(entity.getVariableStructure()));
} }
...@@ -109,7 +111,6 @@ public class AgentApplicationInfoConvert { ...@@ -109,7 +111,6 @@ public class AgentApplicationInfoConvert {
} }
public static AgentApplicationInfoDto entityToDto(BizAgentApplicationInfoEntity entity) { public static AgentApplicationInfoDto entityToDto(BizAgentApplicationInfoEntity entity) {
AgentApplicationBaseInfo baseInfo = new AgentApplicationBaseInfo(); AgentApplicationBaseInfo baseInfo = new AgentApplicationBaseInfo();
baseInfo.setMemberId(entity.getMemberId()); baseInfo.setMemberId(entity.getMemberId());
baseInfo.setAgentId(entity.getAgentId()); baseInfo.setAgentId(entity.getAgentId());
...@@ -127,6 +128,8 @@ public class AgentApplicationInfoConvert { ...@@ -127,6 +128,8 @@ public class AgentApplicationInfoConvert {
commConfig.setContinuousQuestionSystem(entity.getContinuousQuestionSystem()); commConfig.setContinuousQuestionSystem(entity.getContinuousQuestionSystem());
commConfig.setContinuousQuestionTurn(entity.getContinuousQuestionTurn()); commConfig.setContinuousQuestionTurn(entity.getContinuousQuestionTurn());
commConfig.setVariableStructure(entity.getVariableStructure()); commConfig.setVariableStructure(entity.getVariableStructure());
commConfig.setIsLongMemory(entity.getIsLongMemory());
AgentApplicationKnowledgeConfig knowledgeConfig = new AgentApplicationKnowledgeConfig(); AgentApplicationKnowledgeConfig knowledgeConfig = new AgentApplicationKnowledgeConfig();
knowledgeConfig.setKnowledgeIds(entity.getKnowledgeIds()); knowledgeConfig.setKnowledgeIds(entity.getKnowledgeIds());
...@@ -171,6 +174,7 @@ public class AgentApplicationInfoConvert { ...@@ -171,6 +174,7 @@ public class AgentApplicationInfoConvert {
if (ObjectUtil.isNotEmpty(dto.getCommConfig().getVariableStructure())) { if (ObjectUtil.isNotEmpty(dto.getCommConfig().getVariableStructure())) {
entity.setVariableStructure(dto.getCommConfig().getVariableStructure()); entity.setVariableStructure(dto.getCommConfig().getVariableStructure());
} }
entity.setIsLongMemory(dto.getCommConfig().getIsLongMemory());
} }
if (ObjectUtil.isNotEmpty(dto.getKnowledgeConfig())) { if (ObjectUtil.isNotEmpty(dto.getKnowledgeConfig())) {
...@@ -203,6 +207,8 @@ public class AgentApplicationInfoConvert { ...@@ -203,6 +207,8 @@ public class AgentApplicationInfoConvert {
entity.setAgentPublishStatus(infoQueryItem.getAgentPublishStatus()); entity.setAgentPublishStatus(infoQueryItem.getAgentPublishStatus());
entity.setPreamble(infoQueryItem.getPreamble()); entity.setPreamble(infoQueryItem.getPreamble());
entity.setPublishTime(infoQueryItem.getPublishTime()); entity.setPublishTime(infoQueryItem.getPublishTime());
entity.setIsLongMemory(infoQueryItem.getIsLongMemory());
if (StringUtils.isNotBlank(infoQueryItem.getVariableStructure())) { if (StringUtils.isNotBlank(infoQueryItem.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(infoQueryItem.getVariableStructure(), String[].class)); entity.setVariableStructure(JsonUtils.deSerialize(infoQueryItem.getVariableStructure(), String[].class));
} }
......
...@@ -4,9 +4,9 @@ import cn.com.poc.agent_application.domain.AgentApplicationBaseInfo; ...@@ -4,9 +4,9 @@ import cn.com.poc.agent_application.domain.AgentApplicationBaseInfo;
import cn.com.poc.agent_application.domain.AgentApplicationCommConfig; import cn.com.poc.agent_application.domain.AgentApplicationCommConfig;
import cn.com.poc.agent_application.domain.AgentApplicationCommModelConfig; import cn.com.poc.agent_application.domain.AgentApplicationCommModelConfig;
import cn.com.poc.agent_application.domain.AgentApplicationKnowledgeConfig; import cn.com.poc.agent_application.domain.AgentApplicationKnowledgeConfig;
import cn.com.poc.agent_application.model.BizAgentApplicationPublishModel;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto; import cn.com.poc.agent_application.dto.BizAgentApplicationPublishDto;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.poc.agent_application.model.BizAgentApplicationPublishModel;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.tencent.core.utils.JsonUtil; import com.tencent.core.utils.JsonUtil;
...@@ -16,7 +16,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -16,7 +16,7 @@ import org.apache.commons.lang3.StringUtils;
public class BizAgentApplicationPublishConvert { public class BizAgentApplicationPublishConvert {
public static BizAgentApplicationPublishEntity modelToEntity(BizAgentApplicationPublishModel model){ public static BizAgentApplicationPublishEntity modelToEntity(BizAgentApplicationPublishModel model) {
BizAgentApplicationPublishEntity entity = new BizAgentApplicationPublishEntity(); BizAgentApplicationPublishEntity entity = new BizAgentApplicationPublishEntity();
entity.setId(model.getId()); entity.setId(model.getId());
entity.setMemberId(model.getMemberId()); entity.setMemberId(model.getMemberId());
...@@ -26,7 +26,12 @@ public class BizAgentApplicationPublishConvert { ...@@ -26,7 +26,12 @@ public class BizAgentApplicationPublishConvert {
entity.setAgentDesc(model.getAgentDesc()); entity.setAgentDesc(model.getAgentDesc());
entity.setAgentSystem(model.getAgentSystem()); entity.setAgentSystem(model.getAgentSystem());
entity.setPreamble(model.getPreamble()); entity.setPreamble(model.getPreamble());
if(StringUtils.isNotBlank(model.getVariableStructure())) { entity.setIsLongMemory(model.getIsLongMemory());
if (StringUtils.isNotBlank(model.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class));
}
if (StringUtils.isNotBlank(model.getVariableStructure())) {
entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class)); entity.setVariableStructure(JsonUtils.deSerialize(model.getVariableStructure(), String[].class));
} }
if (StringUtils.isNotBlank(model.getFeaturedQuestions())) { if (StringUtils.isNotBlank(model.getFeaturedQuestions())) {
...@@ -53,7 +58,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -53,7 +58,7 @@ public class BizAgentApplicationPublishConvert {
return entity; return entity;
} }
public static BizAgentApplicationPublishModel entityToModel(BizAgentApplicationPublishEntity entity){ public static BizAgentApplicationPublishModel entityToModel(BizAgentApplicationPublishEntity entity) {
BizAgentApplicationPublishModel model = new BizAgentApplicationPublishModel(); BizAgentApplicationPublishModel model = new BizAgentApplicationPublishModel();
model.setId(entity.getId()); model.setId(entity.getId());
model.setMemberId(entity.getMemberId()); model.setMemberId(entity.getMemberId());
...@@ -63,6 +68,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -63,6 +68,7 @@ public class BizAgentApplicationPublishConvert {
model.setAgentDesc(entity.getAgentDesc()); model.setAgentDesc(entity.getAgentDesc());
model.setAgentSystem(entity.getAgentSystem()); model.setAgentSystem(entity.getAgentSystem());
model.setPreamble(entity.getPreamble()); model.setPreamble(entity.getPreamble());
model.setIsLongMemory(entity.getIsLongMemory());
if (ArrayUtils.isNotEmpty(entity.getVariableStructure())) { if (ArrayUtils.isNotEmpty(entity.getVariableStructure())) {
model.setVariableStructure(JsonUtils.serialize(entity.getVariableStructure())); model.setVariableStructure(JsonUtils.serialize(entity.getVariableStructure()));
} }
...@@ -90,7 +96,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -90,7 +96,7 @@ public class BizAgentApplicationPublishConvert {
return model; return model;
} }
public static BizAgentApplicationPublishDto entityToDto(BizAgentApplicationPublishEntity entity){ public static BizAgentApplicationPublishDto entityToDto(BizAgentApplicationPublishEntity entity) {
BizAgentApplicationPublishDto dto = new BizAgentApplicationPublishDto(); BizAgentApplicationPublishDto dto = new BizAgentApplicationPublishDto();
AgentApplicationBaseInfo baseInfo = new AgentApplicationBaseInfo(); AgentApplicationBaseInfo baseInfo = new AgentApplicationBaseInfo();
baseInfo.setMemberId(entity.getMemberId()); baseInfo.setMemberId(entity.getMemberId());
...@@ -109,6 +115,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -109,6 +115,7 @@ public class BizAgentApplicationPublishConvert {
commConfig.setContinuousQuestionSystem(entity.getContinuousQuestionSystem()); commConfig.setContinuousQuestionSystem(entity.getContinuousQuestionSystem());
commConfig.setContinuousQuestionTurn(entity.getContinuousQuestionTurn()); commConfig.setContinuousQuestionTurn(entity.getContinuousQuestionTurn());
commConfig.setVariableStructure(entity.getVariableStructure()); commConfig.setVariableStructure(entity.getVariableStructure());
commConfig.setIsLongMemory(entity.getIsLongMemory());
AgentApplicationKnowledgeConfig knowledgeConfig = new AgentApplicationKnowledgeConfig(); AgentApplicationKnowledgeConfig knowledgeConfig = new AgentApplicationKnowledgeConfig();
knowledgeConfig.setKnowledgeIds(entity.getKnowledgeIds()); knowledgeConfig.setKnowledgeIds(entity.getKnowledgeIds());
...@@ -129,7 +136,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -129,7 +136,7 @@ public class BizAgentApplicationPublishConvert {
return dto; return dto;
} }
public static BizAgentApplicationPublishEntity dtoToEntity(BizAgentApplicationPublishDto dto){ public static BizAgentApplicationPublishEntity dtoToEntity(BizAgentApplicationPublishDto dto) {
BizAgentApplicationPublishEntity entity = new BizAgentApplicationPublishEntity(); BizAgentApplicationPublishEntity entity = new BizAgentApplicationPublishEntity();
if (ObjectUtil.isNotEmpty(dto.getBaseInfo())) { if (ObjectUtil.isNotEmpty(dto.getBaseInfo())) {
entity.setAgentId(dto.getBaseInfo().getAgentId()); entity.setAgentId(dto.getBaseInfo().getAgentId());
...@@ -150,6 +157,7 @@ public class BizAgentApplicationPublishConvert { ...@@ -150,6 +157,7 @@ public class BizAgentApplicationPublishConvert {
entity.setContinuousQuestionStatus(dto.getCommConfig().getContinuousQuestionStatus()); entity.setContinuousQuestionStatus(dto.getCommConfig().getContinuousQuestionStatus());
entity.setContinuousQuestionSystem(dto.getCommConfig().getContinuousQuestionSystem()); entity.setContinuousQuestionSystem(dto.getCommConfig().getContinuousQuestionSystem());
entity.setContinuousQuestionTurn(dto.getCommConfig().getContinuousQuestionTurn()); entity.setContinuousQuestionTurn(dto.getCommConfig().getContinuousQuestionTurn());
entity.setIsLongMemory(dto.getCommConfig().getIsLongMemory());
if (ObjectUtil.isNotEmpty(dto.getCommConfig().getVariableStructure())) { if (ObjectUtil.isNotEmpty(dto.getCommConfig().getVariableStructure())) {
entity.setVariableStructure(dto.getCommConfig().getVariableStructure()); entity.setVariableStructure(dto.getCommConfig().getVariableStructure());
} }
......
...@@ -75,17 +75,32 @@ public class AgentApplicationCommConfig { ...@@ -75,17 +75,32 @@ public class AgentApplicationCommConfig {
this.continuousQuestionTurn = continuousQuestionTurn; this.continuousQuestionTurn = continuousQuestionTurn;
} }
/** variable_structure /**
*变量结构 * variable_structure
* 变量结构
*/ */
private java.lang.String[] variableStructure; private java.lang.String[] variableStructure;
public java.lang.String[] getVariableStructure(){ public java.lang.String[] getVariableStructure() {
return this.variableStructure; return this.variableStructure;
} }
public void setVariableStructure(java.lang.String[] variableStructure){ public void setVariableStructure(java.lang.String[] variableStructure) {
this.variableStructure = variableStructure; this.variableStructure = variableStructure;
} }
/**
* is_long_memory
* 是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
public java.lang.String getIsLongMemory() {
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory) {
this.isLongMemory = isLongMemory;
}
} }
...@@ -232,6 +232,20 @@ public class BizAgentApplicationInfoDto { ...@@ -232,6 +232,20 @@ public class BizAgentApplicationInfoDto {
public void setUnitIds(java.lang.String unitIds){ public void setUnitIds(java.lang.String unitIds){
this.unitIds = unitIds; this.unitIds = unitIds;
} }
/** is_long_memory
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
public java.lang.String getIsLongMemory(){
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory){
this.isLongMemory = isLongMemory;
}
/** is_deleted /** is_deleted
*是否删除 1、Y 是 2、N 否 *是否删除 1、Y 是 2、N 否
*/ */
......
package cn.com.poc.agent_application.entity; package cn.com.poc.agent_application.entity;
import javax.persistence.Column;
import java.util.Arrays; import java.util.Arrays;
public class BizAgentApplicationInfoEntity { public class BizAgentApplicationInfoEntity {
...@@ -247,6 +248,20 @@ public class BizAgentApplicationInfoEntity { ...@@ -247,6 +248,20 @@ public class BizAgentApplicationInfoEntity {
this.variableStructure = variableStructure; this.variableStructure = variableStructure;
} }
/** is_long_memory
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
public java.lang.String getIsLongMemory(){
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory){
this.isLongMemory = isLongMemory;
}
/** is_deleted /** is_deleted
*是否删除 1、Y 是 2、N 否 *是否删除 1、Y 是 2、N 否
*/ */
......
...@@ -246,6 +246,22 @@ public class BizAgentApplicationPublishEntity { ...@@ -246,6 +246,22 @@ public class BizAgentApplicationPublishEntity {
public void setUnitIds(java.lang.String[] unitIds){ public void setUnitIds(java.lang.String[] unitIds){
this.unitIds = unitIds; this.unitIds = unitIds;
} }
/** is_long_memory
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
public java.lang.String getIsLongMemory(){
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory){
this.isLongMemory = isLongMemory;
}
/** is_deleted /** is_deleted
*是否删除 1、Y 是 2、N 否 *是否删除 1、Y 是 2、N 否
*/ */
......
...@@ -344,6 +344,20 @@ public class BizAgentApplicationInfoModel extends BaseModelClass implements Seri ...@@ -344,6 +344,20 @@ public class BizAgentApplicationInfoModel extends BaseModelClass implements Seri
super.addValidField("variableStructure"); super.addValidField("variableStructure");
} }
/** is_long_memory
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
@Column(name = "is_long_memory",length = 1)
public java.lang.String getIsLongMemory(){
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory){
this.isLongMemory = isLongMemory;
super.addValidField("isLongMemory");
}
/** is_deleted /** is_deleted
*是否删除 1、Y 是 2、N 否 *是否删除 1、Y 是 2、N 否
......
...@@ -312,6 +312,20 @@ public class BizAgentApplicationPublishModel extends BaseModelClass implements S ...@@ -312,6 +312,20 @@ public class BizAgentApplicationPublishModel extends BaseModelClass implements S
super.addValidField("unitIds"); super.addValidField("unitIds");
} }
/** is_long_memory
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
@Column(name = "is_long_memory",length = 1)
public java.lang.String getIsLongMemory(){
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory){
this.isLongMemory = isLongMemory;
super.addValidField("isLongMemory");
}
/** is_deleted /** is_deleted
*是否删除 1、Y 是 2、N 否 *是否删除 1、Y 是 2、N 否
......
...@@ -19,6 +19,7 @@ select distinct ...@@ -19,6 +19,7 @@ select distinct
top_p, top_p,
unit_ids, unit_ids,
variable_structure, variable_structure,
is_long_memory,
is_deleted, is_deleted,
CREATOR, CREATOR,
CREATED_TIME, CREATED_TIME,
......
...@@ -314,6 +314,49 @@ public class AgentApplicationInfoQueryItem extends BaseItemClass implements Seri ...@@ -314,6 +314,49 @@ public class AgentApplicationInfoQueryItem extends BaseItemClass implements Seri
this.variableStructure = variableStructure; this.variableStructure = variableStructure;
} }
/** is_long_memory
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isLongMemory;
@Column(name = "is_long_memory",length = 1)
public java.lang.String getIsLongMemory(){
return this.isLongMemory;
}
public void setIsLongMemory(java.lang.String isLongMemory){
this.isLongMemory = isLongMemory;
}
/** function_name
* 方法名
*/
private java.lang.String functionName;
@Column(name = "function_name",length = 2147483647)
public java.lang.String getFunctionName(){
return this.functionName;
}
public void setFunctionName(java.lang.String functionName){
this.functionName = functionName;
}
/** is_function
*是否开启长期记忆 1、Y 是 2、N 否
*/
private java.lang.String isFunction;
@Column(name = "is_function",length = 1)
public java.lang.String getIsFunction(){
return this.isFunction;
}
public void setIsFunction(java.lang.String isFunction){
this.isFunction = isFunction;
}
/** /**
* is_deleted * is_deleted
* is_deleted * is_deleted
......
...@@ -11,17 +11,16 @@ import cn.com.poc.agent_application.rest.AgentApplicationInfoRest; ...@@ -11,17 +11,16 @@ import cn.com.poc.agent_application.rest.AgentApplicationInfoRest;
import cn.com.poc.agent_application.service.BizAgentApplicationInfoService; import cn.com.poc.agent_application.service.BizAgentApplicationInfoService;
import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListService; import cn.com.poc.agent_application.service.BizAgentApplicationLargeModelListService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.common.utils.ListUtils;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Tool;
import cn.com.poc.thirdparty.resource.demand.ai.function.LargeModelFunctionEnum;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -30,7 +29,6 @@ import org.springframework.util.Assert; ...@@ -30,7 +29,6 @@ import org.springframework.util.Assert;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.ListUI;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -144,10 +142,27 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -144,10 +142,27 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
//获取知识库配置 //获取知识库配置
List<Integer> kdIds = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds()); List<Integer> kdIds = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
//配置对话function
List<Tool> tools = new ArrayList<>();
//开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
String functionName = "set_value_memory";
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())) {
String functionName = "set_long_memory";
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getLLMConfig().get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
}
//调用应用服务 //调用应用服务
agentApplicationInfoService.callAgentApplication(infoEntity.getLargeModel(), infoEntity.getUnitIds() agentApplicationInfoService.callAgentApplication(agentId, infoEntity.getLargeModel(), infoEntity.getUnitIds()
, infoEntity.getAgentSystem(), kdIds.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getTopP() , infoEntity.getAgentSystem(), kdIds.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getTopP()
, dto.getMessages(), httpServletResponse); , dto.getMessages(), tools, httpServletResponse);
} catch (Exception e) { } catch (Exception e) {
httpServletResponse.setContentType("text/event-stream"); httpServletResponse.setContentType("text/event-stream");
PrintWriter writer = httpServletResponse.getWriter(); PrintWriter writer = httpServletResponse.getWriter();
......
package cn.com.poc.expose.aggregate.impl; package cn.com.poc.expose.aggregate.impl;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.agent_application.constant.AgentApplicationConstants;
import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants; import cn.com.poc.agent_application.constant.AgentApplicationDialoguesRecordConstants;
import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants; import cn.com.poc.agent_application.constant.AgentApplicationGCConfigConstants;
import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationDialoguesRecordEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationPublishEntity;
import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService; import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordService;
import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService; import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.constant.CommonConstant;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils; import cn.com.poc.common.utils.JsonUtils;
import cn.com.poc.expose.aggregate.AgentApplicationService; import cn.com.poc.expose.aggregate.AgentApplicationService;
import cn.com.poc.expose.dto.AgentApplicationDto;
import cn.com.poc.expose.rest.AgentApplicationRest;
import cn.com.poc.knowledge.aggregate.KnowledgeService; import cn.com.poc.knowledge.aggregate.KnowledgeService;
import cn.com.poc.knowledge.entity.BizKnowledgeInfoEntity;
import cn.com.poc.knowledge.service.BizKnowledgeInfoService;
import cn.com.poc.support.security.oauth.entity.UserBaseEntity; import cn.com.poc.support.security.oauth.entity.UserBaseEntity;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.MultiContent;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Tool;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult; import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelDemandResult;
import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse; import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResponse;
import cn.com.poc.thirdparty.resource.demand.ai.function.LargeModelFunctionEnum;
import cn.com.poc.thirdparty.service.LLMService; import cn.com.poc.thirdparty.service.LLMService;
import cn.com.yict.framemax.core.exception.BusinessException; import cn.com.yict.framemax.core.exception.BusinessException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
...@@ -36,7 +33,6 @@ import org.springframework.stereotype.Service; ...@@ -36,7 +33,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -88,10 +84,26 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -88,10 +84,26 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
List<Message> messages = new ArrayList<>(); List<Message> messages = new ArrayList<>();
buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), messages, input); buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), messages, input);
//配置对话function
List<Tool> tools = new ArrayList<>();
//开启对话变量
if (ArrayUtils.isNotEmpty(infoEntity.getVariableStructure())) {
String functionName = "set_value_memory";
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())) {
String functionName = "set_long_memory";
String llmConfig = LargeModelFunctionEnum.valueOf(functionName).getFunction().getLLMConfig().get(0);
Tool tool = JsonUtils.deSerialize(llmConfig, Tool.class);
tools.add(tool);
}
String output = agentApplicationInfoService.callAgentApplication(infoEntity.getLargeModel(), infoEntity.getUnitIds() String output = agentApplicationInfoService.callAgentApplication(dialogsId, infoEntity.getLargeModel(),
, infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(), infoEntity.getTopP() infoEntity.getUnitIds(), infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(),
, messages, httpServletResponse); infoEntity.getTopP(), messages, tools, httpServletResponse);
//保存对话记录 //保存对话记录
......
...@@ -24,7 +24,7 @@ public interface AgentApplicationRest extends BaseRest { ...@@ -24,7 +24,7 @@ public interface AgentApplicationRest extends BaseRest {
/** /**
* 创建对话 * 创建对话
*/ */
String createDialogues(@RequestParam String agentId) ; String createDialogues(@RequestParam String agentId) throws Exception;
/** /**
* 调用 已发布Agent应用 * 调用 已发布Agent应用
......
package cn.com.poc.thirdparty.resource.demand.ai.common.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Function {
private String name; // 函数名
private String description; // 函数描述
private Map<String, Object> parameters; // 函数请求参数
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Map<String, Object> getParameters() {
return parameters;
}
public void setParameters(Map<String, Object> parameters) {
this.parameters = parameters;
}
@Override
public String toString() {
return "Function{" +
"name='" + name + '\'' +
", description='" + description + '\'' +
", parameters=" + parameters +
'}';
}
}
package cn.com.poc.thirdparty.resource.demand.ai.common.domain;
public class FunctionCall {
private String name;
private String arguments;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getArguments() {
return arguments;
}
public void setArguments(String arguments) {
this.arguments = arguments;
}
}
...@@ -16,6 +16,10 @@ public class Message { ...@@ -16,6 +16,10 @@ public class Message {
private String role; private String role;
private List<FunctionCall> function_call;
private String name;
public List<MultiContent> getContent() { public List<MultiContent> getContent() {
return content; return content;
} }
...@@ -32,11 +36,29 @@ public class Message { ...@@ -32,11 +36,29 @@ public class Message {
this.role = role; this.role = role;
} }
public List<FunctionCall> getFunction_call() {
return function_call;
}
public void setFunction_call(List<FunctionCall> function_call) {
this.function_call = function_call;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override @Override
public String toString() { public String toString() {
return "Message{" + return "Message{" +
"content=" + content + "content=" + content +
", role='" + role + '\'' + ", role='" + role + '\'' +
", function_call=" + function_call +
", name='" + name + '\'' +
'}'; '}';
} }
} }
package cn.com.poc.thirdparty.resource.demand.ai.common.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Tool {
private String type;
private Function function;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Function getFunction() {
return function;
}
public void setFunction(Function function) {
this.function = function;
}
@Override
public String toString() {
return "Tool{" +
"type='" + type + '\'' +
", function=" + function +
'}';
}
}
package cn.com.poc.thirdparty.resource.demand.ai.common.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ToolChoice {
// 属性: type, 必填
private String type;
private ToolFunction toolFunction;
public void setType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public ToolFunction getToolFunction() {
return toolFunction;
}
public void setToolFunction(ToolFunction toolFunction) {
this.toolFunction = toolFunction;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.common.domain;
public class ToolFunction {
private String name;
private String arguments;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getArguments() {
return arguments;
}
public void setArguments(String arguments) {
this.arguments = arguments;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel; package cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel;
import cn.com.poc.support.dgTools.result.AbstractResult; import cn.com.poc.support.dgTools.result.AbstractResult;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.ToolFunction;
import java.io.Serializable; import java.io.Serializable;
...@@ -10,6 +11,10 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab ...@@ -10,6 +11,10 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab
private String message; private String message;
private ToolFunction function;
private String finish_reason;
public String getCode() { public String getCode() {
return code; return code;
} }
...@@ -26,11 +31,29 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab ...@@ -26,11 +31,29 @@ public class LargeModelDemandResult extends AbstractResult implements Serializab
this.message = message; this.message = message;
} }
public ToolFunction getFunction() {
return function;
}
public void setFunction(ToolFunction function) {
this.function = function;
}
public String getFinish_reason() {
return finish_reason;
}
public void setFinish_reason(String finish_reason) {
this.finish_reason = finish_reason;
}
@Override @Override
public String toString() { public String toString() {
return "LargeModelDemandResult{" + return "LargeModelDemandResult{" +
"code='" + code + '\'' + "code='" + code + '\'' +
", message='" + message + '\'' + ", message='" + message + '\'' +
", function=" + function +
", finish_reason='" + finish_reason + '\'' +
'}'; '}';
} }
} }
package cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel; package cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message; import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Tool;
import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
/** /**
...@@ -22,6 +22,8 @@ public class LargeModelResponse implements Serializable { ...@@ -22,6 +22,8 @@ public class LargeModelResponse implements Serializable {
private Message[] messages; private Message[] messages;
private Tool[] tools;
private Float temperature; private Float temperature;
@JsonFilter("top_p") @JsonFilter("top_p")
...@@ -46,6 +48,8 @@ public class LargeModelResponse implements Serializable { ...@@ -46,6 +48,8 @@ public class LargeModelResponse implements Serializable {
private String user; private String user;
private String tool_choice;
public String getModel() { public String getModel() {
return model; return model;
} }
...@@ -142,21 +146,19 @@ public class LargeModelResponse implements Serializable { ...@@ -142,21 +146,19 @@ public class LargeModelResponse implements Serializable {
this.user = user; this.user = user;
} }
@Override public String getTool_choice() {
public String toString() { return tool_choice;
return "LargeModelResponse{" + }
"model='" + model + '\'' +
", messages=" + Arrays.toString(messages) + public void setTool_choice(String tool_choice) {
", temperature=" + temperature + this.tool_choice = tool_choice;
", topP=" + topP + }
", n=" + n +
", stream=" + stream + public Tool[] getTools() {
", stop=" + Arrays.toString(stop) + return tools;
", maxTokens=" + maxTokens + }
", presencePenalty=" + presencePenalty +
", frequencyPenalty=" + frequencyPenalty + public void setTools(Tool[] tools) {
", logit_bias=" + logit_bias + this.tools = tools;
", user='" + user + '\'' +
'}';
} }
} }
package cn.com.poc.thirdparty.resource.demand.ai.function;
import java.util.List;
public abstract class AbstractLargeModelFunction {
public abstract String doFunction(String content, String key);
/**
* 获取配置
*/
public abstract List<String> getLLMConfig();
/**
* 获取有关变量的配置
*/
public abstract List<String> getVariableStructureLLMConfig(String[] variableStructure);
}
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.common.utils.SpringUtils;
public enum LargeModelFunctionEnum {
set_long_memory(SetLongMemoryFunction.class),
set_value_memory(SetValueMemoryFunction.class),
search_memory_content(SearchMemoryContentFunction.class),
search_memory_content_by_enum(SearchMemoryContentByNameFunction.class);
private Class<? extends AbstractLargeModelFunction> function;
LargeModelFunctionEnum(Class<? extends AbstractLargeModelFunction> function) {
this.function = function;
}
public AbstractLargeModelFunction getFunction() {
return SpringUtils.getBean(function);
}
public void setFunction(Class<AbstractLargeModelFunction> function) {
this.function = function;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import cn.hutool.json.JSONObject;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SearchMemoryContentByNameFunction extends AbstractLargeModelFunction {
@Resource
private RedisService redisService;
@Override
public String doFunction(String content, String key) {
// 用enum给定的内容名来查询用户相关信息
// 创建 JSONObject 对象
JSONObject jsonObject = new JSONObject(content);
String contentName = jsonObject.getStr("content");
StringBuffer result = new StringBuffer();
// 先查询变量记忆
String contentKey = key + ":" + BlContext.getCurrentUserNotException().getUserId().toString() + ":" + contentName;
result.append(redisService.get(contentKey));
// 如果短期记忆没查到
return result.toString();
}
@Override
public List<String> getLLMConfig() {
return null;
}
@Override
public List<String> getVariableStructureLLMConfig(String[] variableStructure) {
Map<String, Object> config = new HashMap<>();
Map<String, Object> function = new HashMap<>();
Map<String, Object> parameters = new HashMap<>();
parameters.put("type", "object");
List<String> required = new ArrayList<>();
required.add("content");
parameters.put("required", required);
// 根据变量名查询记忆方法
Map<String, Object> content = new HashMap<>();
content.put("type", "string");
content.put("description", "内容名");
content.put("enum", variableStructure); // 设置变量
Map<String, Object> searchProperties = new HashMap<>();
searchProperties.put("content", content);
parameters.put("properties", searchProperties);
parameters.put("type","object");
function.put("name", "search_memory_content_by_Enum");
function.put("description", "用enum给定的内容名来查询用户信息(什么内容都可以)");
function.put("parameters", parameters);
config.put("type", "function");
config.put("function", function);
// 将 Map 转换为 JSON 字符串
Gson gson = new Gson();
String jsonString = gson.toJson(config);
List<String> resultList = new ArrayList<>();
resultList.add(jsonString);
return resultList;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SearchMemoryContentFunction extends AbstractLargeModelFunction {
@Resource
private RedisService redisService;
@Override
public String doFunction(String content, String key) {
// 查询用户相关信息(什么内容都可以)
String result;
String longMemoryKey = key + ":" + BlContext.getCurrentUserNotException().getUserId().toString() + ":" + "longMemory";
result = redisService.hmget(longMemoryKey).toString();
return result;
}
@Override
public List<String> getLLMConfig() {
Map<String, Object> config = new HashMap<>();
Map<String, Object> function = new HashMap<>();
Map<String, Object> content = new HashMap<>();
content.put("type", "string");
content.put("description","信息说明");
Map<String, Object> properties = new HashMap<>();
properties.put("content", content);
Map<String, Object> parameters = new HashMap<>();
parameters.put("type", "object");
parameters.put("properties",properties);
List<String> required = new ArrayList<>();
required.add("content");
parameters.put("required", required);
function.put("name", "search_memory_content");
function.put("description", "获取用户相关信息");
function.put("parameters", parameters);
config.put("type", "function");
config.put("function", function);
// 将 Map 转换为 JSON 字符串
Gson gson = new Gson();
String jsonString = gson.toJson(config);
List<String> resultList = new ArrayList<>();
resultList.add(jsonString);
return resultList;
}
@Override
public List<String> getVariableStructureLLMConfig(String[] variableStructure) {
return null;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import cn.com.poc.common.utils.DateUtils;
import cn.hutool.json.JSONObject;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SetLongMemoryFunction extends AbstractLargeModelFunction {
@Resource
private RedisService redisService;
@Override
public String doFunction(String content, String key) {
// todo 执行保存长期记忆的操作
// 创建 JSONObject 对象
JSONObject jsonObject = new JSONObject(content);
// 提取 content
String contents = jsonObject.getStr("content");
String contentKey = key + ":" + BlContext.getCurrentUserNotException().getUserId().toString() + ":" + "longMemory";
Map<Object, Object> hmget = redisService.hmget(key);
Map<String, Object> result = new HashMap<>();
for (Map.Entry<Object, Object> entry : hmget.entrySet()) {
if (entry.getKey() instanceof String) {
// 将 Object 强制转换为 String
String tempKey = (String) entry.getKey();
result.put(tempKey, entry.getValue());
}
}
List<String> list = new ArrayList<>();
list.add("timestamp:" + DateUtils.getCurrTime());
list.add("content:" + contents);
result.put(Integer.toString(hmget.size()), list);
redisService.hmset(contentKey, result);
return "SUCCESS";
}
@Override
public List<String> getLLMConfig() {
Map<String, Object> config = new HashMap<>();
Map<String, Object> function = new HashMap<>();
Map<String, Object> content = new HashMap<>();
content.put("type", "string");
content.put("description", "内容的详细说明");
Map<String, Object> properties = new HashMap<>();
properties.put("content", content);
Map<String, Object> parameters = new HashMap<>();
parameters.put("type", "object");
parameters.put("properties", properties);
List<String> required = new ArrayList<>();
required.add("content");
parameters.put("required", required);
function.put("name", "set_long_memory");
function.put("description", "用来保存用户想记录的内容(什么内容都可以)");
function.put("parameters", parameters);
config.put("type", "function");
config.put("function", function);
// 将 Map 转换为 JSON 字符串
Gson gson = new Gson();
String jsonString = gson.toJson(config);
List<String> resultList = new ArrayList<>();
resultList.add(jsonString);
return resultList;
}
@Override
public List<String> getVariableStructureLLMConfig(String[] variableStructure) {
return null;
}
}
package cn.com.poc.thirdparty.resource.demand.ai.function;
import cn.com.poc.common.service.RedisService;
import cn.com.poc.common.utils.BlContext;
import cn.hutool.json.JSONObject;
import com.google.gson.Gson;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class SetValueMemoryFunction extends AbstractLargeModelFunction {
@Resource
private RedisService redisService;
@Override
//todo 保存【变量】方法重构
public String doFunction(String content, String key) {
// todo 执行保存变量的操作
// 创建 JSONObject 对象
JSONObject jsonObject = new JSONObject(content);
// 提取 contentName 和 contentValue
String contentName = jsonObject.getStr("contentName");
String contentValue = jsonObject.getStr("contentValue");
String contentKey = key + ":" + BlContext.getCurrentUserNotException().getUserId().toString() + ":" + contentName;
redisService.set(contentKey, contentValue);
return "SUCCESS";
}
@Override
public List<String> getLLMConfig() {
return null;
}
@Override
public List<String> getVariableStructureLLMConfig(String[] variableStructure) {
Map<String, Object> config = new HashMap<>();
Map<String, Object> function = new HashMap<>();
Map<String, Object> parameters = new HashMap<>();
parameters.put("type", "object");
List<String> required = new ArrayList<>();
required.add("contentName");
required.add("contentValue");
parameters.put("required", required);
Map<String, Object> properties = new HashMap<>();
Map<String, Object> contentName = new HashMap<>();
contentName.put("type", "string");
contentName.put("description", "内容名");
contentName.put("enum", variableStructure); // 设置变量
Map<String, Object> contentValue = new HashMap<>();
contentValue.put("type", "string");
contentValue.put("description", "内容值");
properties.put("contentName", contentName);
properties.put("contentValue", contentValue);
parameters.put("properties", properties);
parameters.put("type", "object");
function.put("name", "set_value_memory");
function.put("description", "用enum给定的内容名来保存用户想记录的内容值");
function.put("parameters", parameters);
config.put("type", "function");
config.put("function", function);
// 将 Map 转换为 JSON 字符串
Gson gson = new Gson();
String jsonString = gson.toJson(config);
List<String> resultList = new ArrayList<>();
resultList.add(jsonString);
return resultList;
}
}
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