Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Anthropic 3 API, Response body is not showing in stacktrace if ChatModel.stream() fails #1583

Open
jombidev opened this issue Oct 22, 2024 · 0 comments

Comments

@jombidev
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant