Commit c65615be authored by alex yao's avatar alex yao

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

parent b417649c
......@@ -19,7 +19,7 @@ public interface BizAgentApplicationDialoguesRecordService extends BaseService {
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);
......
......@@ -121,7 +121,7 @@ public class BizAgentApplicationDialoguesRecordServiceImpl extends BaseServiceIm
return BizAgentApplicationDialoguesRecordConvert.modelToEntity(saveModel);
}
public void deletedById(java.lang.Long id) throws Exception {
public void deletedById(Long id) {
Assert.notNull(id);
BizAgentApplicationDialoguesRecordModel model = this.repository.get(id);
if (model != null) {
......
......@@ -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.BizAgentApplicationPublishService;
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.utils.BlContext;
import cn.com.poc.common.utils.JsonUtils;
......@@ -40,7 +39,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.*;
@Service
public class AgentApplicationServiceImpl implements AgentApplicationService {
......@@ -72,16 +70,15 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
@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();
if (userBaseEntity == null) {
throw new BusinessException("用户未登录");
}
// 记录输入时间戳
Long inputTimestamp = System.currentTimeMillis();
Long userRecordId = null;
try {
BizAgentApplicationPublishEntity infoEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (infoEntity == null) {
logger.warn("can not find agent application , agent_id:{}", agentId);
......@@ -96,20 +93,46 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
//获取知识库配置
List<Integer> kdIdList = knowledgeService.getKdIdsByKnowledgeInfoIds(infoEntity.getKnowledgeIds());
// 记录输入时间戳
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);
//保存对话记录
saveDialoguesRecord(dialogsId, input, infoEntity, userBaseEntity, inputTimestamp, output);
outputRecord.setContent(output);
bizAgentApplicationDialoguesRecordService.save(outputRecord);
} catch (Exception e) {
if (userRecordId != null){
bizAgentApplicationDialoguesRecordService.deletedById(userRecordId);
}
}
}
......
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