Commit c65615be authored by alex yao's avatar alex yao

fix:期望用户发送信息后就会生成历史记录,而不是等回答完才生成

parent b417649c
...@@ -19,7 +19,7 @@ public interface BizAgentApplicationDialoguesRecordService extends BaseService { ...@@ -19,7 +19,7 @@ public interface BizAgentApplicationDialoguesRecordService extends BaseService {
BizAgentApplicationDialoguesRecordEntity update(BizAgentApplicationDialoguesRecordEntity entity) throws Exception; BizAgentApplicationDialoguesRecordEntity update(BizAgentApplicationDialoguesRecordEntity entity) throws Exception;
void deletedById(java.lang.Long id) throws Exception; void deletedById(java.lang.Long id) ;
List<BizAgentApplicationDialoguesRecordEntity> getRecord(String agentId, Integer turn); List<BizAgentApplicationDialoguesRecordEntity> getRecord(String agentId, Integer turn);
......
...@@ -121,7 +121,7 @@ public class BizAgentApplicationDialoguesRecordServiceImpl extends BaseServiceIm ...@@ -121,7 +121,7 @@ public class BizAgentApplicationDialoguesRecordServiceImpl extends BaseServiceIm
return BizAgentApplicationDialoguesRecordConvert.modelToEntity(saveModel); return BizAgentApplicationDialoguesRecordConvert.modelToEntity(saveModel);
} }
public void deletedById(java.lang.Long id) throws Exception { public void deletedById(Long id) {
Assert.notNull(id); Assert.notNull(id);
BizAgentApplicationDialoguesRecordModel model = this.repository.get(id); BizAgentApplicationDialoguesRecordModel model = this.repository.get(id);
if (model != null) { if (model != null) {
......
...@@ -10,7 +10,6 @@ import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordSe ...@@ -10,7 +10,6 @@ import cn.com.poc.agent_application.service.BizAgentApplicationDialoguesRecordSe
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.constant.CommonConstant;
import cn.com.poc.common.pool.CommonThreadPoolExecutor;
import cn.com.poc.common.service.RedisService; import cn.com.poc.common.service.RedisService;
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;
...@@ -40,7 +39,6 @@ import java.util.ArrayList; ...@@ -40,7 +39,6 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.*;
@Service @Service
public class AgentApplicationServiceImpl implements AgentApplicationService { public class AgentApplicationServiceImpl implements AgentApplicationService {
...@@ -72,44 +70,69 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -72,44 +70,69 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@Override @Override
public void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) throws Exception { public void callAgentApplication(String agentId, String dialogsId, String input, HttpServletResponse httpServletResponse) {
UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException(); UserBaseEntity userBaseEntity = BlContext.getCurrentUserNotException();
if (userBaseEntity == null) { if (userBaseEntity == null) {
throw new BusinessException("用户未登录"); throw new BusinessException("用户未登录");
} }
// 记录输入时间戳 Long userRecordId = null;
Long inputTimestamp = System.currentTimeMillis(); try {
BizAgentApplicationPublishEntity infoEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (infoEntity == null) {
logger.warn("can not find agent application , agent_id:{}", agentId);
throw new BusinessException("未找到应用");
}
BizAgentApplicationPublishEntity infoEntity = bizAgentApplicationPublishService.getByAgentId(agentId); if (StringUtils.isBlank(dialogsId)) {
if (infoEntity == null) { // 用于针对只有单Agent应用分享使用的场景,dialogsId为空
logger.warn("can not find agent application , agent_id:{}", agentId); dialogsId = agentId + "_" + userBaseEntity.getUserId();
throw new BusinessException("未找到应用"); }
}
if (StringUtils.isBlank(dialogsId)) { //获取知识库配置
// 用于针对只有单Agent应用分享使用的场景,dialogsId为空 List<Integer> kdIdList = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
dialogsId = agentId + "_" + userBaseEntity.getUserId();
// 记录输入时间戳
Long inputTimestamp = System.currentTimeMillis();
BizAgentApplicationDialoguesRecordEntity inputRecord = new BizAgentApplicationDialoguesRecordEntity();
inputRecord.setAgentId(agentId);
inputRecord.setMemberId(userBaseEntity.getUserId());
inputRecord.setContent(input);
inputRecord.setDialogsId(dialogsId);
inputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
inputRecord.setTimestamp(inputTimestamp);
BizAgentApplicationDialoguesRecordEntity saveRecord = bizAgentApplicationDialoguesRecordService.save(inputRecord);
userRecordId = saveRecord.getId();
// 构造对话参数
List<Message> messages = buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), input);
//配置对话function
List<Tool> tools = buildMemoryConfig(infoEntity);
// 记录输出时间戳
BizAgentApplicationDialoguesRecordEntity outputRecord = new BizAgentApplicationDialoguesRecordEntity();
outputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.ASSISTANT);
outputRecord.setAgentId(infoEntity.getAgentId());
outputRecord.setDialogsId(dialogsId);
outputRecord.setMemberId(userBaseEntity.getUserId());
outputRecord.setTimestamp(System.currentTimeMillis());
//对话
String output = agentApplicationInfoService.callAgentApplication(dialogsId, infoEntity.getLargeModel(),
infoEntity.getUnitIds(), infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(),
infoEntity.getTopP(), infoEntity.getTemperature(), messages, tools, httpServletResponse);
//保存对话记录
outputRecord.setContent(output);
bizAgentApplicationDialoguesRecordService.save(outputRecord);
} catch (Exception e) {
if (userRecordId != null){
bizAgentApplicationDialoguesRecordService.deletedById(userRecordId);
}
} }
//获取知识库配置
List<Integer> kdIdList = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
// 构造对话参数
List<Message> messages = buildMessages(dialogsId, agentId, userBaseEntity.getUserId(), input);
//配置对话function
List<Tool> tools = buildMemoryConfig(infoEntity);
//对话
String output = agentApplicationInfoService.callAgentApplication(dialogsId, infoEntity.getLargeModel(),
infoEntity.getUnitIds(), infoEntity.getAgentSystem(), kdIdList.toArray(new Integer[0]), infoEntity.getCommunicationTurn(),
infoEntity.getTopP(), infoEntity.getTemperature(), messages, tools, httpServletResponse);
//保存对话记录
saveDialoguesRecord(dialogsId, input, infoEntity, userBaseEntity, inputTimestamp, output);
} }
......
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