Commit 20f7ab64 authored by alex yao's avatar alex yao

feat: handle large model session parameter exceptions

parent ed056161
...@@ -86,7 +86,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -86,7 +86,6 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
throw new BusinessException("用户未登录"); throw new BusinessException("用户未登录");
} }
Long userRecordId = null;
try { try {
BizAgentApplicationPublishEntity infoEntity = bizAgentApplicationPublishService.getByAgentId(agentId); BizAgentApplicationPublishEntity infoEntity = bizAgentApplicationPublishService.getByAgentId(agentId);
if (infoEntity == null) { if (infoEntity == null) {
...@@ -118,8 +117,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -118,8 +117,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
inputRecord.setDialogsId(dialogsId); inputRecord.setDialogsId(dialogsId);
inputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER); inputRecord.setRole(AgentApplicationDialoguesRecordConstants.ROLE.USER);
inputRecord.setTimestamp(inputTimestamp); inputRecord.setTimestamp(inputTimestamp);
BizAgentApplicationDialoguesRecordEntity saveRecord = bizAgentApplicationDialoguesRecordService.save(inputRecord); bizAgentApplicationDialoguesRecordService.save(inputRecord);
userRecordId = saveRecord.getId();
// 记录输出时间戳 // 记录输出时间戳
...@@ -139,9 +137,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -139,9 +137,7 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
outputRecord.setContent(output); outputRecord.setContent(output);
bizAgentApplicationDialoguesRecordService.save(outputRecord); bizAgentApplicationDialoguesRecordService.save(outputRecord);
} catch (Exception e) { } catch (Exception e) {
if (userRecordId != null) { throw new BusinessException(e.getMessage());
bizAgentApplicationDialoguesRecordService.deletedById(userRecordId);
}
} }
} }
...@@ -266,6 +262,15 @@ public class AgentApplicationServiceImpl implements AgentApplicationService { ...@@ -266,6 +262,15 @@ public class AgentApplicationServiceImpl implements AgentApplicationService {
messages.add(message); messages.add(message);
} }
} }
//判断最后是否为User,若是则删除。
if (LLMRoleEnum.USER.getRole().equals(messages.get(messages.size() - 1).getRole())) {
Long recordId = recordEntities.get(recordEntities.size() - 1).getId();
bizAgentApplicationDialoguesRecordService.deletedById(recordId);
messages.remove(messages.size() - 1);
}
// 用户输入
Message message = new Message(); Message message = new Message();
message.setContent(input); message.setContent(input);
message.setRole(LLMRoleEnum.USER.getRole()); message.setRole(LLMRoleEnum.USER.getRole());
......
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