Bug description

on call of AnthropicChatModel.stream (method signature: org.springframework.ai.anthropic.AnthropicChatModel#stream(Lorg/springframework/ai/chat/prompt/Prompt;)Lreactor/core/publisher/Flux;), thrown exception's response body is not displaying correctly. Screenshot 2024-10-22 at 14 31 39

At the AnthropicApi#110, ClientResponse#bodyToMono is never used as Publisher. I don't think it's intentional. It should display the body of error request, instead of Mono<T>#toString(). Screenshot 2024-10-22 at 14 05 28

Environment

Amazon Corretto 17 (OpenJDK 17) Spring Boot - 3.3.0 Spring AI - 1.0.0-M3

Minimal Complete Reproducible example

Here is simple java code to reproduce:

AnthropicApi api = new AnthropicApi("LEAVING_IT_EMPTY");
StreamingChatModel model = new AnthropicChatModel(api, new AnthropicChatOptions());

model.stream(new Prompt("Hello, world!"))
        .doOnEach((res) -> System.out.println(res.get()))
        .blockLast();

Screenshot 2024-10-22 at 14 51 05

Expected behavior

It can be displayed by passing WebClient builder in constructor of AnthropicApi, but it should display at default. Await the mono variable. we can get body as String properly. Screenshot 2024-10-22 at 14 58 23

changing Mono.just~~ to below code:

resp
.bodyToMono(java.lang.String.class)
.map((body) -> new RuntimeException("Response exception, Status: [" + resp.statusCode() +
                  "], Body:[" + body + "]"))

Will work as expected.

Comment From: DHKIM-0511

Fix PR https://github.com/spring-projects/spring-ai/pull/1721

Comment From: markpollack

Sorry, we should have closed this issue last Friday, the fix already in main and was part of this commit 9fa89a2fd65dba03bd27b26ac49fd32a9fab558a

Comment From: jombidev

I have confirmed that the issue has been resolved, but written commit log is not correct. here is the fixed commit: https://github.com/spring-projects/spring-ai/commit/fb2e7528d0b74ae4adcb4aa6e18436bff2e808e5