Skip to content

Commit c65fdac

Browse files
committed
Perf(prompt-chat-memory) : Remove repeated getConversationId(...) calls
Signed-off-by: KoreaNirsa <[email protected]>
1 parent 290d676 commit c65fdac

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

spring-ai-client-chat/src/main/java/org/springframework/ai/chat/client/advisor/PromptChatMemoryAdvisor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,17 @@ else if (chatClientResponse.chatResponse() != null) {
155155
}
156156

157157
if (!assistantMessages.isEmpty()) {
158-
this.chatMemory.add(this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
159-
assistantMessages);
158+
String cid = this.getConversationId(chatClientResponse.context(), this.defaultConversationId);
159+
this.chatMemory.add(cid, assistantMessages);
160160

161161
if (logger.isDebugEnabled()) {
162162
logger.debug(
163163
"[PromptChatMemoryAdvisor.after] Added ASSISTANT messages to memory for conversationId={}: {}",
164-
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
164+
cid,
165165
assistantMessages);
166-
List<Message> memoryMessages = this.chatMemory
167-
.get(this.getConversationId(chatClientResponse.context(), this.defaultConversationId));
166+
List<Message> memoryMessages = this.chatMemory.get(cid);
168167
logger.debug("[PromptChatMemoryAdvisor.after] Memory after ASSISTANT add for conversationId={}: {}",
169-
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
168+
cid,
170169
memoryMessages);
171170
}
172171
}

0 commit comments

Comments
 (0)