Skip to content

anthropic-ai thinking error #3371

@walle1027

Description

@walle1027

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();

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions