Skip to content

Commit 2778ec6

Browse files
authored
Use Optional to check null in DefaultChatClient#doGetObservableFluxChatResponse (#3976)
Signed-off-by: Mengqi Xu <[email protected]>
1 parent 42df693 commit 2778ec6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,10 @@ public Flux<String> content() {
548548
// @formatter:off
549549
return doGetObservableFluxChatResponse(this.request)
550550
.mapNotNull(ChatClientResponse::chatResponse)
551-
.map(r -> {
552-
if (r.getResult() == null || r.getResult().getOutput() == null
553-
|| r.getResult().getOutput().getText() == null) {
554-
return "";
555-
}
556-
return r.getResult().getOutput().getText();
557-
})
551+
.map(r -> Optional.ofNullable(r.getResult())
552+
.map(Generation::getOutput)
553+
.map(AbstractMessage::getText)
554+
.orElse(""))
558555
.filter(StringUtils::hasLength);
559556
// @formatter:on
560557
}

0 commit comments

Comments
 (0)