Bug description
Caused by: com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Could not resolve type id 'thinking' as a subtype of org.springframework.ai.anthropic.api.AnthropicApi$ContentBlockStartEvent$ContentBlockBody
: known type ids = [text, tool_use] (for POJO property 'content_block')
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION
disabled); line: 1, column: 65] (through reference chain: org.springframework.ai.anthropic.api.AnthropicApi$ContentBlockStartEvent["content_block"])
Environment
spring-ai: 1.0.0
java: 23
Steps to reproduce
AnthropicApi.Builder builder = AnthropicApi.builder();
builder.webClientBuilder(WebClient.builder());
builder.restClientBuilder(RestClient.builder());
builder.anthropicBetaFeatures("max-tokens-3-5-sonnet-2024-07-15");
builder.baseUrl("https://api.anthropic.com");
builder.apiKey("sk-xxxxxxxxxx");
AnthropicChatOptions.Builder optionBuilder = AnthropicChatOptions.builder();
optionBuilder.model( AnthropicApi.ChatModel.CLAUDE_3_7_SONNET.getValue());
optionBuilder.temperature(1.0);
optionBuilder.maxTokens(1024 * 16);
optionBuilder.thinking(AnthropicApi.ThinkingType.ENABLED,10000);
AnthropicChatModel.Builder modelBuilder = AnthropicChatModel.builder();
modelBuilder.anthropicApi(builder.build());
modelBuilder.observationRegistry(observationRegistry);
modelBuilder.defaultOptions(optionBuilder.build());
modelBuilder.toolCallingManager(toolCallingManager);
modelBuilder.retryTemplate(retryTemplate);
var chatModel = modelBuilder.build();
chatModel.stream(new Prompt("what's the weather about tomorrow")).filter(response -> response.getResult() != null).doOnNext(response -> {
Generation result = response.getResult();
AssistantMessage assistantMessage = result.getOutput();
if (assistantMessage != null) {
System.out.println(assistantMessage);
System.out.println(assistantMessage.getText());
}
}).blockLast();
Comment From: apappascs
Thank you for the input @walle1027 . this seems dublicate of this one https://github.com/spring-projects/spring-ai/issues/2793
to be honest AnthropicApi.ThinkingType.ENABLED
was not delivered for chatModel.stream
but for blocking calls only. It should have been communicated better on the documentation. Here is the PR to resolve the issue https://github.com/spring-projects/spring-ai/pull/2800