Skip to content

Commit f7acaa2

Browse files
author
aliqingdong
committed
fix: Remove unreachable else-if branch in PromptChatMemoryAdvisor
Signed-off-by: aliqingdong <[email protected]>
1 parent 72ed429 commit f7acaa2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,18 @@ public ChatClientRequest before(ChatClientRequest chatClientRequest, AdvisorChai
141141
@Override
142142
public ChatClientResponse after(ChatClientResponse chatClientResponse, AdvisorChain advisorChain) {
143143
List<Message> assistantMessages = new ArrayList<>();
144-
if (chatClientResponse.chatResponse() != null) {
144+
// Handle streaming case where we have a single result
145+
if (chatClientResponse.chatResponse() != null && chatClientResponse.chatResponse().getResult() != null
146+
&& chatClientResponse.chatResponse().getResult().getOutput() != null) {
147+
assistantMessages = List.of((Message) chatClientResponse.chatResponse().getResult().getOutput());
148+
}
149+
else if (chatClientResponse.chatResponse() != null) {
145150
assistantMessages = chatClientResponse.chatResponse()
146151
.getResults()
147152
.stream()
148153
.map(g -> (Message) g.getOutput())
149154
.toList();
150155
}
151-
// Handle streaming case where we have a single result
152-
else if (chatClientResponse.chatResponse() != null && chatClientResponse.chatResponse().getResult() != null
153-
&& chatClientResponse.chatResponse().getResult().getOutput() != null) {
154-
assistantMessages = List.of((Message) chatClientResponse.chatResponse().getResult().getOutput());
155-
}
156156

157157
if (!assistantMessages.isEmpty()) {
158158
this.chatMemory.add(this.getConversationId(chatClientResponse.context(), this.defaultConversationId),

0 commit comments

Comments
 (0)