|
26 | 26 | import java.util.HashMap; |
27 | 27 | import java.util.List; |
28 | 28 | import java.util.Map; |
| 29 | +import java.util.Optional; |
29 | 30 | import java.util.concurrent.ConcurrentHashMap; |
30 | 31 | import java.util.function.Consumer; |
31 | 32 |
|
|
48 | 49 | import org.springframework.ai.chat.client.observation.ChatClientObservationConvention; |
49 | 50 | import org.springframework.ai.chat.client.observation.ChatClientObservationDocumentation; |
50 | 51 | import org.springframework.ai.chat.client.observation.DefaultChatClientObservationConvention; |
| 52 | +import org.springframework.ai.chat.messages.AbstractMessage; |
51 | 53 | import org.springframework.ai.chat.messages.Message; |
52 | 54 | import org.springframework.ai.chat.messages.MessageType; |
53 | 55 | import org.springframework.ai.chat.messages.UserMessage; |
54 | 56 | import org.springframework.ai.chat.model.ChatModel; |
55 | 57 | import org.springframework.ai.chat.model.ChatResponse; |
| 58 | +import org.springframework.ai.chat.model.Generation; |
56 | 59 | import org.springframework.ai.chat.model.StreamingChatModel; |
57 | 60 | import org.springframework.ai.chat.model.ToolContext; |
58 | 61 | import org.springframework.ai.chat.prompt.ChatOptions; |
@@ -493,11 +496,11 @@ private ChatResponse doGetChatResponse(DefaultChatClientRequestSpec inputRequest |
493 | 496 |
|
494 | 497 | @Nullable |
495 | 498 | private static String getContentFromChatResponse(@Nullable ChatResponse chatResponse) { |
496 | | - if (chatResponse == null || chatResponse.getResult() == null || chatResponse.getResult().getOutput() == null |
497 | | - || chatResponse.getResult().getOutput().getText() == null) { |
498 | | - return null; |
499 | | - } |
500 | | - return chatResponse.getResult().getOutput().getText(); |
| 499 | + return Optional.ofNullable(chatResponse) |
| 500 | + .map(ChatResponse::getResult) |
| 501 | + .map(Generation::getOutput) |
| 502 | + .map(AbstractMessage::getText) |
| 503 | + .orElse(null); |
501 | 504 | } |
502 | 505 |
|
503 | 506 | @Override |
|
0 commit comments