Skip to content

Commit 71e56fb

Browse files
authored
feat(anthropic): add support for claude-opus-4 and claude-sonnet-4 (#3351)
* feat(anthropic): add support for claude-opus-4-0 and claude-sonnet-4-0 models - Introduce `CLAUDE_OPUS_4` and `CLAUDE_SONNET_4` to `ChatModel` enum - Update documentation to include new model options Signed-off-by: Alexandros Pappas <[email protected]> * add model aliases url to anthropic documentation Signed-off-by: Alexandros Pappas <[email protected]> --------- Signed-off-by: Alexandros Pappas <[email protected]>
1 parent 3a527ee commit 71e56fb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

models/spring-ai-anthropic/src/main/java/org/springframework/ai/anthropic/api/AnthropicApi.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ public Flux<ChatCompletionResponse> chatCompletionStream(ChatCompletionRequest c
241241
public enum ChatModel implements ChatModelDescription {
242242

243243
// @formatter:off
244+
/**
245+
* The claude-opus-4-0 model.
246+
*/
247+
CLAUDE_OPUS_4("claude-opus-4-0"),
248+
249+
/**
250+
* The claude-sonnet-4-0 model.
251+
*/
252+
CLAUDE_SONNET_4("claude-sonnet-4-0"),
253+
244254
/**
245255
* The claude-3-7-sonnet-latest model.
246256
*/

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/anthropic-chat.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ The prefix `spring.ai.anthropic` is used as the property prefix that lets you co
124124
| spring.ai.anthropic.completions-path | The path to append to the base URL. | `/v1/chat/completions`
125125
| spring.ai.anthropic.version | Anthropic API version | 2023-06-01
126126
| spring.ai.anthropic.api-key | The API Key | -
127-
| spring.ai.anthropic.beta-version | Enables new/experimental features. If set to `max-tokens-3-5-sonnet-2024-07-15`
127+
| spring.ai.anthropic.beta-version | Enables new/experimental features. If set to `max-tokens-3-5-sonnet-2024-07-15`
128128
the output tokens limit is increased from `4096` to `8192` tokens (for claude-3-5-sonnet only). | `tools-2024-04-04`
129129
|====
130130

@@ -149,7 +149,7 @@ The prefix `spring.ai.anthropic.chat` is the property prefix that lets you confi
149149

150150
| spring.ai.anthropic.chat.enabled (Removed and no longer valid) | Enable Anthropic chat model. | true
151151
| spring.ai.model.chat | Enable Anthropic chat model. | anthropic
152-
| spring.ai.anthropic.chat.options.model | This is the Anthropic Chat model to use. Supports: `claude-3-7-sonnet-latest`, `claude-3-5-sonnet-latest`, `claude-3-opus-20240229`, `claude-3-sonnet-20240229`, `claude-3-haiku-20240307` | `claude-3-7-sonnet-latest`
152+
| spring.ai.anthropic.chat.options.model | This is the Anthropic Chat model to use. Supports: `claude-opus-4-0`, `claude-sonnet-4-0`, `claude-3-7-sonnet-latest`, `claude-3-5-sonnet-latest`, `claude-3-opus-20240229`, `claude-3-sonnet-20240229`, `claude-3-haiku-20240307` | `claude-3-7-sonnet-latest`
153153
| spring.ai.anthropic.chat.options.temperature | The sampling temperature to use that controls the apparent creativity of generated completions. Higher values will make output more random while lower values will make results more focused and deterministic. It is not recommended to modify temperature and top_p for the same completions request as the interaction of these two settings is difficult to predict. | 0.8
154154
| spring.ai.anthropic.chat.options.max-tokens | The maximum number of tokens to generate in the chat completion. The total length of input tokens and generated tokens is limited by the model's context length. | 500
155155
| spring.ai.anthropic.chat.options.stop-sequence | Custom text sequences that will cause the model to stop generating. Our models will normally stop when they have naturally completed their turn, which will result in a response stop_reason of "end_turn". If you want the model to stop generating when it encounters custom strings of text, you can use the stop_sequences parameter. If the model encounters one of the custom sequences, the response stop_reason value will be "stop_sequence" and the response stop_sequence value will contain the matched stop sequence. | -
@@ -164,6 +164,8 @@ The prefix `spring.ai.anthropic.chat` is the property prefix that lets you confi
164164
| spring.ai.anthropic.chat.options.http-headers | Optional HTTP headers to be added to the chat completion request. | -
165165
|====
166166

167+
TIP: For the latest list of model aliases and their descriptions, see the link:https://docs.anthropic.com/en/docs/about-claude/models/overview#model-aliases[official Anthropic model aliases documentation].
168+
167169
TIP: All properties prefixed with `spring.ai.anthropic.chat.options` can be overridden at runtime by adding a request specific <<chat-options>> to the `Prompt` call.
168170

169171
== Runtime Options [[chat-options]]
@@ -262,7 +264,7 @@ spring.ai.anthropic.chat.options.temperature=0.7
262264
spring.ai.anthropic.chat.options.max-tokens=450
263265
----
264266

265-
TIP: replace the `api-key` with your Anthropic credentials.
267+
TIP: Replace the `api-key` with your Anthropic credentials.
266268

267269
This will create a `AnthropicChatModel` implementation that you can inject into your class.
268270
Here is an example of a simple `@Controller` class that uses the chat model for text generations.

0 commit comments

Comments
 (0)