fix: Remove unreachable else-if branch in PromptChatMemoryAdvisor (#3395)

Fixes: #3395

Auto-cherry-pick to 1.0.x

Signed-off-by: aliqingdong <229436569@qq.com>
Co-authored-by: aliqingdong <229436569@qq.com>
This commit is contained in:
azurelee
2025-05-30 22:34:27 +08:00
committed by Soby Chacko
parent 7f93f03e52
commit 72da79714c

View File

@@ -141,18 +141,18 @@ public final class PromptChatMemoryAdvisor implements BaseChatMemoryAdvisor {
@Override
public ChatClientResponse after(ChatClientResponse chatClientResponse, AdvisorChain advisorChain) {
List<Message> assistantMessages = new ArrayList<>();
if (chatClientResponse.chatResponse() != null) {
// Handle streaming case where we have a single result
if (chatClientResponse.chatResponse() != null && chatClientResponse.chatResponse().getResult() != null
&& chatClientResponse.chatResponse().getResult().getOutput() != null) {
assistantMessages = List.of((Message) chatClientResponse.chatResponse().getResult().getOutput());
}
else if (chatClientResponse.chatResponse() != null) {
assistantMessages = chatClientResponse.chatResponse()
.getResults()
.stream()
.map(g -> (Message) g.getOutput())
.toList();
}
// Handle streaming case where we have a single result
else if (chatClientResponse.chatResponse() != null && chatClientResponse.chatResponse().getResult() != null
&& chatClientResponse.chatResponse().getResult().getOutput() != null) {
assistantMessages = List.of((Message) chatClientResponse.chatResponse().getResult().getOutput());
}
if (!assistantMessages.isEmpty()) {
this.chatMemory.add(this.getConversationId(chatClientResponse.context(), this.defaultConversationId),