diff --git a/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java b/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java index fef3ea3..e316989 100644 --- a/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/ChatMessageServiceImpl.java @@ -224,37 +224,37 @@ public class ChatMessageServiceImpl implements ChatMessageService { SseHelper.send(sseEmitter, "[DONE]"); // 处理完成后的事件: 保存消息记录, 缓存更改 ChatSession.Message message = ChatSession.Message.of(userPrompt, s); - HistoryCache.updateContext(sessionId, message); + HistoryCache.updateContext(userId, message); CosmosPatchOperations options = CosmosPatchOperations.create() .replace("/updateTime", Instant.now().toEpochMilli()) .add("/history/-", message); - chatSessionRepository.save(sessionId, PK.of(PK.CHAT_SESSION), ChatSession.class, options); + chatSessionRepository.save(userId, PK.of(PK.CHAT_SESSION), ChatSession.class, options); }); // 错误的回调 listener.setOnError((s) -> { log.error("callback: ws error, info: " + s); // 返还积分 }); - List messageList = fetchContext(sessionId, userPrompt); + List messageList = fetchContext(userId, userPrompt); SparkChatRequestParam requestParam = SparkChatRequestParam .builder() .uid(userId) - .chatId(sessionId) + .chatId(userId) .messageList(messageList) .build(); sparkGptClient.streamChatCompletion(requestParam, listener); return sseEmitter; } - List fetchContext(String sessionId, String prompt) { - List context = HistoryCache.getContext(sessionId); + List fetchContext(String userId, String prompt) { + List context = HistoryCache.getContext(userId); List paramMessages = new ArrayList<>(); // 暂未缓存,从数据库拉取 if (ObjectUtils.isEmpty(context)) { - context = chatSessionRepository.findLatestMessage(sessionId); + context = chatSessionRepository.findLatestMessage(userId); if (ObjectUtils.isNotEmpty(context)) { - HistoryCache.putContext(sessionId, context); + HistoryCache.putContext(userId, context); } }