Skip to content

Commit e45b1b3

Browse files
authored
perf(logging): optimize debug logging in PromptChatMemoryAdvisor (#3448)
- Enclosed debug logging statements within an isDebugEnabled() check - Reduced unnecessary method calls and object creations when debug logging is disabled Auto-cherry-pick to 1.0.x Signed-off-by: Ahoo Wang <ahoowang@qq.com>
1 parent 925def2 commit e45b1b3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,18 @@ else if (chatClientResponse.chatResponse() != null) {
157157
if (!assistantMessages.isEmpty()) {
158158
this.chatMemory.add(this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
159159
assistantMessages);
160-
logger.debug("[PromptChatMemoryAdvisor.after] Added ASSISTANT messages to memory for conversationId={}: {}",
161-
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
162-
assistantMessages);
163-
List<Message> memoryMessages = this.chatMemory
164-
.get(this.getConversationId(chatClientResponse.context(), this.defaultConversationId));
165-
logger.debug("[PromptChatMemoryAdvisor.after] Memory after ASSISTANT add for conversationId={}: {}",
166-
this.getConversationId(chatClientResponse.context(), this.defaultConversationId), memoryMessages);
160+
161+
if (logger.isDebugEnabled()) {
162+
logger.debug(
163+
"[PromptChatMemoryAdvisor.after] Added ASSISTANT messages to memory for conversationId={}: {}",
164+
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
165+
assistantMessages);
166+
List<Message> memoryMessages = this.chatMemory
167+
.get(this.getConversationId(chatClientResponse.context(), this.defaultConversationId));
168+
logger.debug("[PromptChatMemoryAdvisor.after] Memory after ASSISTANT add for conversationId={}: {}",
169+
this.getConversationId(chatClientResponse.context(), this.defaultConversationId),
170+
memoryMessages);
171+
}
167172
}
168173
return chatClientResponse;
169174
}

0 commit comments

Comments
 (0)