From d173babbd74163b177a9e15baef65cff657594eb Mon Sep 17 00:00:00 2001 From: PL <774412461@qq.com> Date: Tue, 20 Aug 2024 15:41:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AF=84=E8=AF=AD=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ChatMessageServiceImpl.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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); } }