Commit 3a613015 authored by alex yao's avatar alex yao

feat:Agent应用 AI配置生成

parent 0f7b3735
...@@ -17,7 +17,44 @@ public interface AgentApplicationInfoService { ...@@ -17,7 +17,44 @@ public interface AgentApplicationInfoService {
* 应用预览 * 应用预览
*/ */
String callAgentApplication(String largeModel, String[] unitIds, String agentSystem, String callAgentApplication(String largeModel, String[] unitIds, String agentSystem,
String[] knowledgeIds, Integer communicationTurn, Float topP, String[] knowledgeIds, Integer communicationTurn, Float topP,
List<Message> messages, HttpServletResponse httpServletResponse) throws Exception; List<Message> messages, HttpServletResponse httpServletResponse) throws Exception;
/**
* 角色指令AI生成
*
* @param input
* @param httpServletResponse
* @return
*/
void createAgentSystem(String input, HttpServletResponse httpServletResponse) throws Exception;
/**
* 开场白AI生成
*
* @param agentTitle 应用标题
* @param agentDesc 应用描述
* @return
*/
String createPreamble(String agentTitle, String agentDesc);
/**
* 推荐问题AI生成
*
* @param agentTitle
* @param agentDesc
* @return
* @throws Exception
*/
List<String> createFeaturedQuestions(String agentTitle, String agentDesc);
/**
* 追问AI生成
*
* @param messages@return
*/
List<String> createContinueQuestions(List<Message> messages, String agentId);
} }
...@@ -3,8 +3,11 @@ package cn.com.poc.agent_application.aggregate.impl; ...@@ -3,8 +3,11 @@ package cn.com.poc.agent_application.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.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.entity.BizAgentApplicationGcConfigEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity; 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.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.service.BizAgentApplicationInfoService; import cn.com.poc.agent_application.service.BizAgentApplicationInfoService;
import cn.com.poc.agent_application.service.BizAgentApplicationPublishService; import cn.com.poc.agent_application.service.BizAgentApplicationPublishService;
import cn.com.poc.common.utils.BlContext; import cn.com.poc.common.utils.BlContext;
...@@ -18,6 +21,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResp ...@@ -18,6 +21,7 @@ import cn.com.poc.thirdparty.resource.demand.ai.entity.largemodel.LargeModelResp
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 cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -44,6 +48,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -44,6 +48,8 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
final private Logger logger = LoggerFactory.getLogger(AgentApplicationInfoService.class); final private Logger logger = LoggerFactory.getLogger(AgentApplicationInfoService.class);
@Resource
private BizAgentApplicationGcConfigService bizAgentApplicationGcConfigService;
@Resource @Resource
private BizAgentApplicationInfoService bizAgentApplicationInfoService; private BizAgentApplicationInfoService bizAgentApplicationInfoService;
...@@ -77,7 +83,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -77,7 +83,7 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
} }
@Override @Override
public String callAgentApplication(String largeModel, String[] unitIds, String agentSystem, public String callAgentApplication(String largeModel, String[] unitIds, String agentSystem,
String[] knowledgeIds, Integer communicationTurn, Float topP, String[] knowledgeIds, Integer communicationTurn, Float topP,
List<Message> messages, HttpServletResponse httpServletResponse) throws Exception { List<Message> messages, HttpServletResponse httpServletResponse) throws Exception {
logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" + logger.info("--------- Call Agent Application large model:{},unitIds:{},agentSystem:{},knowledgeIds:{}" +
...@@ -93,6 +99,179 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ ...@@ -93,6 +99,179 @@ public class AgentApplicationInfoServiceImpl implements AgentApplicationInfoServ
return textOutput(httpServletResponse, bufferedReader); return textOutput(httpServletResponse, bufferedReader);
} }
@Override
public void createAgentSystem(String input, HttpServletResponse httpServletResponse) throws Exception {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_SYSTEM);
if (null == configEntity) {
throw new BusinessException("创建[角色指令]配置不存在");
}
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(new MultiContent() {{
String configSystem = configEntity.getConfigSystem();
configSystem = configSystem.replace("${input}", input);
setText(configSystem);
setType("text");
}});
Message message = new Message();
message.setContent(multiContents);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
List<Message> messages = new ArrayList<Message>() {{
add(message);
}};
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(messages.toArray(new Message[1]));
largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-CREATE-AGENT-SYSTEM");
BufferedReader bufferedReader = llmService.chatChunk(largeModelResponse);
textOutput(httpServletResponse, bufferedReader);
}
@Override
public String createPreamble(String agentTitle, String agentDesc) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_PREAMBLE);
if (null == configEntity) {
throw new BusinessException("创建[开场白]配置不存在");
}
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(new MultiContent() {{
String configSystem = configEntity.getConfigSystem();
configSystem = configSystem.replace("${agent_title}", agentTitle);
configSystem = configSystem.replace("${agent_desc}", agentDesc);
setText(configSystem);
setType("text");
}});
Message message = new Message();
message.setContent(multiContents);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
List<Message> messages = new ArrayList<Message>() {{
add(message);
}};
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(messages.toArray(new Message[1]));
largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-CREATE-PREAMBLE");
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
return largeModelDemandResult.getMessage();
}
@Override
public List<String> createFeaturedQuestions(String agentTitle, String agentDesc) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_FEATURED_QUESTIONS);
if (null == configEntity) {
throw new BusinessException("创建[开场白]配置不存在");
}
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(new MultiContent() {{
String configSystem = configEntity.getConfigSystem();
configSystem = configSystem.replace("${agent_title}", agentTitle);
configSystem = configSystem.replace("${agent_desc}", agentDesc);
setText(configSystem);
setType("text");
}});
Message message = new Message();
message.setContent(multiContents);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
List<Message> messages = new ArrayList<Message>() {{
add(message);
}};
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(messages.toArray(new Message[1]));
largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-FEATURED-QUESTIONS");
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
String res = largeModelDemandResult.getMessage();
int start = res.lastIndexOf("[");
int end = res.lastIndexOf("]");
return JsonUtils.deSerialize(res.substring(start, end + 1), new TypeReference<List<String>>() {
}.getType());
}
@Override
public List<String> createContinueQuestions(List<Message> messages, String agentId) {
BizAgentApplicationGcConfigEntity configEntity = bizAgentApplicationGcConfigService.getByConfigCode(AgentApplicationGCConfigConstants.AGENT_CONTINUE_QUESTIONS);
if (null == configEntity) {
throw new BusinessException("创建[开场白]配置不存在");
}
BizAgentApplicationInfoEntity infoEntity = bizAgentApplicationInfoService.getByAgentId(agentId);
String continuousQuestionStatus = infoEntity.getContinuousQuestionStatus();
if (AgentApplicationConstants.CONTINUOUS_QUESTION_STATUS.CLOSE.equals(continuousQuestionStatus)) {
logger.warn("连续问题已关闭");
return null;
}
String configSystem = configEntity.getConfigSystem();
int turn = 3;
if (AgentApplicationConstants.CONTINUOUS_QUESTION_STATUS.CUSTOMIZABLE.equals(continuousQuestionStatus)) {
configSystem = configSystem.replace("${input}", infoEntity.getContinuousQuestionSystem());
turn = infoEntity.getContinuousQuestionTurn();
}
MultiContent systemMultiContent = new MultiContent();
systemMultiContent.setText(configSystem);
systemMultiContent.setType("text");
List<MultiContent> multiContents = new ArrayList<>();
multiContents.add(systemMultiContent);
Message systemMessage = new Message();
systemMessage.setContent(multiContents);
systemMessage.setRole(AgentApplicationDialoguesRecordConstants.ROLE.SYSTEM);
int messLength = messages.size() - 1;
int skip = turn * 2;
if (skip < messLength) {
messages = messages.subList(messLength - skip, messages.size());
}
StringBuilder userBuilder = new StringBuilder();
for (Message message : messages) {
userBuilder.append(message.getRole()).append(":").append(message.getContent().get(0).getText()).append(StringUtils.LF);
}
MultiContent multiContent = new MultiContent();
multiContent.setText(userBuilder.toString());
multiContent.setType("text");
List<MultiContent> userMultiContent = new ArrayList<>();
userMultiContent.add(multiContent);
Message message = new Message();
message.setContent(userMultiContent);
message.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
LargeModelResponse largeModelResponse = new LargeModelResponse();
largeModelResponse.setModel(configEntity.getLargeModel());
largeModelResponse.setMessages(new ArrayList<Message>() {{
add(systemMessage);
add(message);
}}.toArray(new Message[2]));
largeModelResponse.setTopP(configEntity.getTopP());
largeModelResponse.setUser("POC-CONTINUE-QUESTIONS");
LargeModelDemandResult largeModelDemandResult = llmService.chat(largeModelResponse);
String res = largeModelDemandResult.getMessage();
int start = res.lastIndexOf("[");
int end = res.lastIndexOf("]");
return JsonUtils.deSerialize(res.substring(start, end + 1), new TypeReference<List<String>>() {
}.getType());
}
private String buildDialogsPrompt(List<Message> messages, String agentSystem, String[] knowledgeIds) { private String buildDialogsPrompt(List<Message> messages, String agentSystem, String[] knowledgeIds) {
// todo 获取提示词模板 // todo 获取提示词模板
String promptTemplate = "${agentSystem}"; String promptTemplate = "${agentSystem}";
......
package cn.com.poc.agent_application.constant;
public interface AgentApplicationGCConfigConstants {
String AGENT_SYSTEM = "AgentSystem";
String AGENT_PREAMBLE = "AgentPreamble";
String AGENT_FEATURED_QUESTIONS = "AgentFeaturedQuestions";
String AGENT_CONTINUE_QUESTIONS = "AgentContinueQuestions";
}
package cn.com.poc.agent_application.convert;
import cn.com.poc.agent_application.model.BizAgentApplicationGcConfigModel;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
public class BizAgentApplicationGcConfigConvert {
public static BizAgentApplicationGcConfigEntity modelToEntity(BizAgentApplicationGcConfigModel model){
BizAgentApplicationGcConfigEntity entity = new BizAgentApplicationGcConfigEntity();
entity.setId(model.getId());
entity.setConfigCode(model.getConfigCode());
entity.setConfigSystem(model.getConfigSystem());
entity.setLargeModel(model.getLargeModel());
entity.setTopP(model.getTopP());
return entity;
}
public static BizAgentApplicationGcConfigModel entityToModel(BizAgentApplicationGcConfigEntity entity){
BizAgentApplicationGcConfigModel model = new BizAgentApplicationGcConfigModel();
model.setId(entity.getId());
model.setConfigCode(entity.getConfigCode());
model.setConfigSystem(entity.getConfigSystem());
model.setLargeModel(entity.getLargeModel());
model.setTopP(entity.getTopP());
return model;
}
}
\ No newline at end of file
package cn.com.poc.agent_application.dto;
import cn.com.poc.thirdparty.resource.demand.ai.common.domain.Message;
import java.io.Serializable;
import java.util.List;
public class AgentApplicationCreateContinueQuesDto implements Serializable {
private List<Message> messages;
public List<Message> getMessages() {
return messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
}
package cn.com.poc.agent_application.dto;
import java.io.Serializable;
public class AgentApplicationGCDto implements Serializable {
private String input;
private String agentTitle;
private String agentDesc;
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getAgentTitle() {
return agentTitle;
}
public void setAgentTitle(String agentTitle) {
this.agentTitle = agentTitle;
}
public String getAgentDesc() {
return agentDesc;
}
public void setAgentDesc(String agentDesc) {
this.agentDesc = agentDesc;
}
}
package cn.com.poc.agent_application.entity;
public class BizAgentApplicationGcConfigEntity {
/** id
*
*/
private java.lang.Integer id;
public java.lang.Integer getId(){
return this.id;
}
public void setId(java.lang.Integer id){
this.id = id;
}
/** config_code
*配置代码
*/
private java.lang.String configCode;
public java.lang.String getConfigCode(){
return this.configCode;
}
public void setConfigCode(java.lang.String configCode){
this.configCode = configCode;
}
/** config_system
*提示词
*/
private java.lang.String configSystem;
public java.lang.String getConfigSystem(){
return this.configSystem;
}
public void setConfigSystem(java.lang.String configSystem){
this.configSystem = configSystem;
}
/** large_model
*大模型
*/
private java.lang.String largeModel;
public java.lang.String getLargeModel(){
return this.largeModel;
}
public void setLargeModel(java.lang.String largeModel){
this.largeModel = largeModel;
}
/** top_p
*多样性
*/
private java.lang.Float topP;
public java.lang.Float getTopP(){
return this.topP;
}
public void setTopP(java.lang.Float topP){
this.topP = topP;
}
}
\ No newline at end of file
package cn.com.poc.agent_application.model;
import java.io.Serializable;
import cn.com.yict.framemax.data.model.BaseModelClass;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
/**
* Model class for biz_agent_application_gc_config
* agent应用 AI生成【提示词-大模型配置】
*/
@Entity
@Table(name = "biz_agent_application_gc_config")
@DynamicInsert
@DynamicUpdate
public class BizAgentApplicationGcConfigModel extends BaseModelClass implements Serializable {
private static final long serialVersionUID = 1L;
/** id
*
*/
private java.lang.Integer id;
@Column(name = "id",length = 10)
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public java.lang.Integer getId(){
return this.id;
}
public void setId(java.lang.Integer id){
this.id = id;
super.addValidField("id");
}
/** config_code
*配置代码
*/
private java.lang.String configCode;
@Column(name = "config_code",length = 100)
public java.lang.String getConfigCode(){
return this.configCode;
}
public void setConfigCode(java.lang.String configCode){
this.configCode = configCode;
super.addValidField("configCode");
}
/** config_system
*提示词
*/
private java.lang.String configSystem;
@Column(name = "config_system",length = 2147483647)
public java.lang.String getConfigSystem(){
return this.configSystem;
}
public void setConfigSystem(java.lang.String configSystem){
this.configSystem = configSystem;
super.addValidField("configSystem");
}
/** large_model
*大模型
*/
private java.lang.String largeModel;
@Column(name = "large_model",length = 100)
public java.lang.String getLargeModel(){
return this.largeModel;
}
public void setLargeModel(java.lang.String largeModel){
this.largeModel = largeModel;
super.addValidField("largeModel");
}
/** top_p
*多样性
*/
private java.lang.Float topP;
@Column(name = "top_p",length = 12)
public java.lang.Float getTopP(){
return this.topP;
}
public void setTopP(java.lang.Float topP){
this.topP = topP;
super.addValidField("topP");
}
}
\ No newline at end of file
package cn.com.poc.agent_application.repository;
import cn.com.yict.framemax.data.repository.Repository;
import cn.com.poc.agent_application.model.BizAgentApplicationGcConfigModel;
public interface BizAgentApplicationGcConfigRepository extends Repository<BizAgentApplicationGcConfigModel,java.lang.Integer> {
}
\ No newline at end of file
package cn.com.poc.agent_application.rest; package cn.com.poc.agent_application.rest;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto; import cn.com.poc.agent_application.dto.*;
import cn.com.poc.agent_application.dto.AgentApplicationPreviewDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationLargeModelListDto;
import cn.com.yict.framemax.core.rest.BaseRest; import cn.com.yict.framemax.core.rest.BaseRest;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto;
import cn.com.yict.framemax.data.model.PagingInfo; import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.List; import java.util.List;
...@@ -58,4 +55,25 @@ public interface AgentApplicationInfoRest extends BaseRest { ...@@ -58,4 +55,25 @@ public interface AgentApplicationInfoRest extends BaseRest {
* 获取应用模型列表 * 获取应用模型列表
*/ */
List<BizAgentApplicationLargeModelListDto> getLargeModelList() throws Exception; List<BizAgentApplicationLargeModelListDto> getLargeModelList() throws Exception;
/**
* 角色指令AI生成
*/
void createAgentSystem(@RequestBody AgentApplicationGCDto dto, HttpServletResponse response) throws Exception;
/**
* [推荐问]生成
*/
List<String> createFeaturedQuestions(@RequestBody AgentApplicationGCDto dto) throws Exception;
/**
* 开场白AI生成
*/
String createPreamble(@RequestBody AgentApplicationGCDto dto) throws Exception;
/**
* 追问
*/
List<String> createContinueQuestions(@RequestBody AgentApplicationCreateContinueQuesDto dto, @RequestParam String agentId) throws Exception;
} }
\ No newline at end of file
...@@ -3,10 +3,7 @@ package cn.com.poc.agent_application.rest.impl; ...@@ -3,10 +3,7 @@ package cn.com.poc.agent_application.rest.impl;
import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService; import cn.com.poc.agent_application.aggregate.AgentApplicationInfoService;
import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert; import cn.com.poc.agent_application.convert.AgentApplicationInfoConvert;
import cn.com.poc.agent_application.convert.BizAgentApplicationLargeModelListConvert; import cn.com.poc.agent_application.convert.BizAgentApplicationLargeModelListConvert;
import cn.com.poc.agent_application.dto.AgentApplicationInfoDto; import cn.com.poc.agent_application.dto.*;
import cn.com.poc.agent_application.dto.AgentApplicationInfoSearchDto;
import cn.com.poc.agent_application.dto.AgentApplicationPreviewDto;
import cn.com.poc.agent_application.dto.BizAgentApplicationLargeModelListDto;
import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationInfoEntity;
import cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity; import cn.com.poc.agent_application.entity.BizAgentApplicationLargeModelListEntity;
import cn.com.poc.agent_application.query.AgentApplicationInfoQueryCondition; import cn.com.poc.agent_application.query.AgentApplicationInfoQueryCondition;
...@@ -145,4 +142,26 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest { ...@@ -145,4 +142,26 @@ public class AgentApplicationInfoRestImpl implements AgentApplicationInfoRest {
.map(BizAgentApplicationLargeModelListConvert::entityToDto) .map(BizAgentApplicationLargeModelListConvert::entityToDto)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public void createAgentSystem(AgentApplicationGCDto dto, HttpServletResponse response) throws Exception {
Assert.notNull(dto.getInput(), "输入不能为空");
agentApplicationInfoService.createAgentSystem(dto.getInput(), response);
}
@Override
public List<String> createFeaturedQuestions(AgentApplicationGCDto dto) throws Exception {
return agentApplicationInfoService.createFeaturedQuestions(dto.getAgentTitle(), dto.getAgentDesc());
}
@Override
public String createPreamble(AgentApplicationGCDto dto) throws Exception {
return agentApplicationInfoService.createPreamble(dto.getAgentTitle(), dto.getAgentDesc());
}
@Override
public List<String> createContinueQuestions(AgentApplicationCreateContinueQuesDto dto, String agentId) throws Exception {
return agentApplicationInfoService.createContinueQuestions(dto.getMessages(), agentId);
}
} }
\ No newline at end of file
package cn.com.poc.agent_application.service;
import cn.com.yict.framemax.core.service.BaseService;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
import cn.com.yict.framemax.data.model.PagingInfo;
import java.util.Collection;
import java.util.List;
public interface BizAgentApplicationGcConfigService extends BaseService {
BizAgentApplicationGcConfigEntity getByConfigCode(String configCode) ;
BizAgentApplicationGcConfigEntity get(java.lang.Integer id) throws Exception;
List<BizAgentApplicationGcConfigEntity> findByExample(BizAgentApplicationGcConfigEntity example,PagingInfo pagingInfo) throws Exception;
BizAgentApplicationGcConfigEntity save(BizAgentApplicationGcConfigEntity entity) throws Exception;
BizAgentApplicationGcConfigEntity update(BizAgentApplicationGcConfigEntity entity) throws Exception;
void deletedById(java.lang.Integer id) throws Exception;
}
\ No newline at end of file
package cn.com.poc.agent_application.service.impl;
import cn.com.yict.framemax.core.service.impl.BaseServiceImpl;
import cn.com.poc.agent_application.service.BizAgentApplicationGcConfigService;
import cn.com.poc.agent_application.model.BizAgentApplicationGcConfigModel;
import cn.com.poc.agent_application.entity.BizAgentApplicationGcConfigEntity;
import cn.com.poc.agent_application.convert.BizAgentApplicationGcConfigConvert;
import cn.com.poc.agent_application.repository.BizAgentApplicationGcConfigRepository;
import cn.com.yict.framemax.data.model.PagingInfo;
import org.springframework.stereotype.Service;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.util.Assert;
@Service
public class BizAgentApplicationGcConfigServiceImpl extends BaseServiceImpl
implements BizAgentApplicationGcConfigService {
@Resource
private BizAgentApplicationGcConfigRepository repository;
@Override
public BizAgentApplicationGcConfigEntity getByConfigCode(String configCode) {
Assert.notNull(configCode);
BizAgentApplicationGcConfigModel model = new BizAgentApplicationGcConfigModel();
model.setConfigCode(configCode);
List<BizAgentApplicationGcConfigModel> models = this.repository.findByExample(model);
if (CollectionUtils.isNotEmpty(models)) {
return BizAgentApplicationGcConfigConvert.modelToEntity(models.get(0));
}
return null;
}
public BizAgentApplicationGcConfigEntity get(java.lang.Integer id) throws Exception {
Assert.notNull(id);
BizAgentApplicationGcConfigModel model = this.repository.get(id);
if (model == null) {
return null;
}
return BizAgentApplicationGcConfigConvert.modelToEntity(model);
}
public List<BizAgentApplicationGcConfigEntity> findByExample(BizAgentApplicationGcConfigEntity example, PagingInfo pagingInfo) throws Exception {
List<BizAgentApplicationGcConfigEntity> result = new ArrayList<BizAgentApplicationGcConfigEntity>();
BizAgentApplicationGcConfigModel model = new BizAgentApplicationGcConfigModel();
if (example != null) {
model = BizAgentApplicationGcConfigConvert.entityToModel(example);
}
List<BizAgentApplicationGcConfigModel> models = this.repository.findByExample(model, pagingInfo);
if (CollectionUtils.isNotEmpty(models)) {
result = models.stream().map(BizAgentApplicationGcConfigConvert::modelToEntity).collect(Collectors.toList());
}
return result;
}
public BizAgentApplicationGcConfigEntity save(BizAgentApplicationGcConfigEntity entity) throws Exception {
Assert.notNull(entity);
entity.setId(null);
BizAgentApplicationGcConfigModel model = BizAgentApplicationGcConfigConvert.entityToModel(entity);
BizAgentApplicationGcConfigModel saveModel = this.repository.save(model);
return BizAgentApplicationGcConfigConvert.modelToEntity(saveModel);
}
public BizAgentApplicationGcConfigEntity update(BizAgentApplicationGcConfigEntity entity) throws Exception {
Assert.notNull(entity);
Assert.notNull(entity.getId(), "update pk can not be null");
BizAgentApplicationGcConfigModel model = this.repository.get(entity.getId());
if (entity.getConfigCode() != null) {
model.setConfigCode(entity.getConfigCode());
}
if (entity.getConfigSystem() != null) {
model.setConfigSystem(entity.getConfigSystem());
}
if (entity.getLargeModel() != null) {
model.setLargeModel(entity.getLargeModel());
}
if (entity.getTopP() != null) {
model.setTopP(entity.getTopP());
}
BizAgentApplicationGcConfigModel saveModel = this.repository.save(model);
return BizAgentApplicationGcConfigConvert.modelToEntity(saveModel);
}
public void deletedById(java.lang.Integer id) throws Exception {
Assert.notNull(id);
BizAgentApplicationGcConfigModel model = this.repository.get(id);
if (model != null) {
}
}
}
\ No newline at end of file
...@@ -23,5 +23,5 @@ public interface AIDialogueService { ...@@ -23,5 +23,5 @@ public interface AIDialogueService {
/** /**
* 调用中台通用大模型接口 [非流] * 调用中台通用大模型接口 [非流]
*/ */
LargeModelDemandResult poly(LargeModelResponse largeResponse) throws Exception; LargeModelDemandResult poly(LargeModelResponse largeResponse) ;
} }
...@@ -58,7 +58,7 @@ public class AIDialogueServiceImpl implements AIDialogueService { ...@@ -58,7 +58,7 @@ public class AIDialogueServiceImpl implements AIDialogueService {
} }
@Override @Override
public LargeModelDemandResult poly(LargeModelResponse largeResponse) throws Exception { public LargeModelDemandResult poly(LargeModelResponse largeResponse) {
largeResponse.setStream(false); largeResponse.setStream(false);
LargeModelDemandResponse response = new LargeModelDemandResponse(); LargeModelDemandResponse response = new LargeModelDemandResponse();
response.setApiKey(API_KEY); response.setApiKey(API_KEY);
...@@ -83,7 +83,7 @@ public class AIDialogueServiceImpl implements AIDialogueService { ...@@ -83,7 +83,7 @@ public class AIDialogueServiceImpl implements AIDialogueService {
} }
private LargeModelDemandResult largeModelRequest(LargeModelDemandResponse request) { private LargeModelDemandResult largeModelRequest(LargeModelDemandResponse request) {
String url = DOMAIN_URL + DgtoolsApiConstants.BASE_URL + DgtoolsApiConstants.DgtoolsAI.LARGE_MODEL; String url = DgtoolsApiConstants.DgtoolsAI.LARGE_MODEL;
List<Header> headers = new ArrayList<Header>() {{ List<Header> headers = new ArrayList<Header>() {{
add(DgtoolsApiConstants.JSON_HEADER); add(DgtoolsApiConstants.JSON_HEADER);
add(DgtoolsApiConstants.AI_HEADER); add(DgtoolsApiConstants.AI_HEADER);
......
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