4.2 每日总结(开发智能体-2)

@CrossOrigin
@GetMapping("/ai/resetChatMemory")
public String resetChatMemory() {
String tokenValue = StpUtil.getTokenValue();
String userId = StpUtil.getLoginIdByToken(tokenValue).toString();

UUID conversationId = chatSessionManager.getSession(userId);
if (conversationId != null) {
// 清空会话记忆
chatMemory.clear(String.valueOf(conversationId));
chatSessionManager.removeSession(userId);
return "已清空该用户:" + userId + "的会话记录";
} else {
return "没有会话记录因为无此用户:" + userId;
}
}

// 获取会话记忆
@GetMapping("ai/getChatMemory")
public List<Message> getChatMemory() {
String tokenValue = StpUtil.getTokenValue();
String userId = StpUtil.getLoginIdByToken(tokenValue).toString();
UUID conversationId = chatSessionManager.getSession(userId);
if (conversationId != null) {
return chatMemory.get(String.valueOf(conversationId),40);
}
return null;
}
posted @ 2025-04-09 11:57  笠大  阅读(25)  评论(0)    收藏  举报