You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/bedrock/bedrock-anthropic.adoc
+82-80Lines changed: 82 additions & 80 deletions
Original file line number
Diff line number
Diff line change
@@ -10,62 +10,11 @@ The Claude model has the following high level features
10
10
11
11
The https://aws.amazon.com/bedrock/claude[AWS Bedrock Anthropic Model Page] and https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html[Amazon Bedrock User Guide] contains detailed information on how to use the AWS hosted model.
12
12
13
-
== Getting Started
13
+
== Pre-requisites
14
14
15
15
Refer to the xref:api/clients/bedrock.adoc[Spring AI documentation on Amazon Bedrock] for setting up API access.
16
16
17
-
The link:./src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java[BedrockAnthropicChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the `AnthropicChatBedrockApi` library to connect to the Bedrock Anthropic service.
18
-
19
-
Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file:
NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
40
-
41
-
Next, create an `BedrockAnthropicChatClient` instance and use it to text generations requests:
42
-
43
-
[source,java]
44
-
----
45
-
AnthropicChatBedrockApi anthropicApi = new AnthropicChatBedrockApi(
new Prompt("Generate the names of 5 famous pirates."));
62
-
63
-
// Or with streaming responses
64
-
Flux<ChatResponse> response = chatClient.stream(
65
-
new Prompt("Generate the names of 5 famous pirates."));
66
-
----
67
-
68
-
=== AnthropicChatClient Auto-configuration
17
+
== Auto-configuration
69
18
70
19
or you can leverage the `spring-ai-bedrock-ai-spring-boot-starter` Spring Boot starter:
71
20
@@ -78,18 +27,50 @@ or you can leverage the `spring-ai-bedrock-ai-spring-boot-starter` Spring Boot s
78
27
</dependency>
79
28
----
80
29
81
-
==== Enable Anthropic Support
30
+
=== Enable Anthropic Support
82
31
83
32
Spring AI defines a configuration property named `spring.ai.bedrock.anthropic.chat.enabled` that you should set to `true` to enable support for Anthropic.
84
-
85
33
Exporting environment variables in one way to set this configuration property.
| spring.ai.bedrock.anthropic.chat.model | The model id to use. See the `AnthropicChatModel` for the supported models. | anthropic.claude-v2
61
+
| spring.ai.bedrock.anthropic.chat.options.temperature | Controls the randomness of the output. Values can range over [0.0,1.0] | 0.8
62
+
| spring.ai.bedrock.anthropic.chat.options.topP | The maximum cumulative probability of tokens to consider when sampling. | AWS Bedrock default
63
+
| spring.ai.bedrock.anthropic.chat.options.topK | Specify the number of token choices the generative uses to generate the next token. | AWS Bedrock default
64
+
| spring.ai.bedrock.anthropic.chat.options.stopSequences | Configure up to four sequences that the generative recognizes. After a stop sequence, the generative stops generating further tokens. The returned text doesn't contain the stop sequence. | 10
65
+
| spring.ai.bedrock.anthropic.chat.options.anthropicVersion | The version of the generative to use. | bedrock-2023-05-31
66
+
| spring.ai.bedrock.anthropic.chat.options.maxTokensToSample | Specify the maximum number of tokens to use in the generated response. Note that the models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate. We recommend a limit of 4,000 tokens for optimal performance. | 500
67
+
|====
68
+
69
+
Look at the Spring AI enumeration `AnthropicChatModel` for other model IDs. The other value supported is `anthropic.claude-instant-v1`.
70
+
71
+
Model ID values can also be found in the https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html[AWS Bedrock documentation for base model IDs].
72
+
73
+
=== Sample Code
93
74
94
75
This will create a `ChatClient` implementation that you can inject into your class.
95
76
@@ -122,38 +103,59 @@ public class ChatController {
122
103
}
123
104
----
124
105
125
-
==== Bedrock Properties
106
+
== Manual Configuration
126
107
127
-
The prefix `spring.ai.bedrock.aws` is the property prefix to configure the connection to AWS Bedrock.
108
+
The link:./src/main/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatClient.java[BedrockAnthropicChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the `AnthropicChatBedrockApi` library to connect to the Bedrock Anthropic service.
128
109
129
-
[cols="3,3,1"]
130
-
|====
131
-
| Property | Description | Default
110
+
Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file:
132
111
133
-
| spring.ai.bedrock.aws.region | AWS region to use. | us-east-1
| spring.ai.bedrock.anthropic.chat.model | The model id to use. See the `AnthropicChatModel` for the supported models. | anthropic.claude-v2
146
-
| spring.ai.bedrock.anthropic.chat.options.temperature | Controls the randomness of the output. Values can range over [0.0,1.0] | 0.8
147
-
| spring.ai.bedrock.anthropic.chat.options.topP | The maximum cumulative probability of tokens to consider when sampling. | AWS Bedrock default
148
-
| spring.ai.bedrock.anthropic.chat.options.topK | Specify the number of token choices the generative uses to generate the next token. | AWS Bedrock default
149
-
| spring.ai.bedrock.anthropic.chat.options.stopSequences | Configure up to four sequences that the generative recognizes. After a stop sequence, the generative stops generating further tokens. The returned text doesn't contain the stop sequence. | 10
150
-
| spring.ai.bedrock.anthropic.chat.options.anthropicVersion | The version of the generative to use. | bedrock-2023-05-31
151
-
| spring.ai.bedrock.anthropic.chat.options.maxTokensToSample | Specify the maximum number of tokens to use in the generated response. Note that the models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate. We recommend a limit of 4,000 tokens for optimal performance. | 500
152
-
|====
130
+
NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
153
131
154
-
Look at the Spring AI enumeration `AnthropicChatModel` for other model IDs. The other value supported is `anthropic.claude-instant-v1`.
132
+
Next, create an `BedrockAnthropicChatClient` instance and use it to text generations requests:
133
+
134
+
[source,java]
135
+
----
136
+
AnthropicChatBedrockApi anthropicApi = new AnthropicChatBedrockApi(
new Prompt("Generate the names of 5 famous pirates."));
153
+
154
+
// Or with streaming responses
155
+
Flux<ChatResponse> response = chatClient.stream(
156
+
new Prompt("Generate the names of 5 famous pirates."));
157
+
----
155
158
156
-
Model ID values can also be found in the https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html[AWS Bedrock documentation for base model IDs].
Copy file name to clipboardExpand all lines: spring-ai-docs/src/main/antora/modules/ROOT/pages/api/clients/bedrock/bedrock-llama2.adoc
+72-73Lines changed: 72 additions & 73 deletions
Original file line number
Diff line number
Diff line change
@@ -9,58 +9,11 @@ Rigorous testing, including over 1,000 hours of red-teaming and annotation, ensu
9
9
10
10
The https://aws.amazon.com/bedrock/llama-2/[AWS Llama 2 Model Page] and https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html[Amazon Bedrock User Guide] contains detailed information on how to use the AWS hosted model.
11
11
12
-
13
-
== Getting Started
12
+
== Prerequisites
14
13
15
14
Refer to the xref:api/clients/bedrock.adoc[Spring AI documentation on Amazon Bedrock] for setting up API access.
16
15
17
-
18
-
Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file:
NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
39
-
40
-
The link:./src/main/java/org/springframework/ai/bedrock/llama2/BedrockLlama2ChatClient.java[BedrockLlama2ChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the `Llama2ChatBedrockApi` library to connect to the Bedrock Llama2 service.
41
-
42
-
Here is how to create and use a `BedrockLlama2ChatClient`:
43
-
44
-
[source,java]
45
-
----
46
-
Llama2ChatBedrockApi api = new Llama2ChatBedrockApi(Llama2ChatModel.LLAMA2_70B_CHAT_V1.id(),
47
-
EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), new ObjectMapper());
48
-
49
-
BedrockLlama2ChatClient chatClient = new BedrockLlama2ChatClient(api,
50
-
BedrockLlama2ChatOptions.builder()
51
-
.withTemperature(0.5f)
52
-
.withMaxGenLen(100)
53
-
.withTopP(0.9f).build());
54
-
55
-
ChatResponse response = chatClient.call(
56
-
new Prompt("Generate the names of 5 famous pirates."));
57
-
58
-
// Or with streaming responses
59
-
Flux<ChatResponse> response = chatClient.stream(
60
-
new Prompt("Generate the names of 5 famous pirates."));
61
-
----
62
-
63
-
=== BedrockLlama2ChatClient Auto-configuration
16
+
== Auto-configuration
64
17
65
18
or you can leverage the `spring-ai-bedrock-ai-spring-boot-starter` Spring Boot starter:
66
19
@@ -82,18 +35,48 @@ dependencies {
82
35
}
83
36
----
84
37
85
-
==== Enable Llama2 Chat Support
38
+
=== Enable Llama2 Chat Support
86
39
87
40
Spring AI defines a configuration property named `spring.ai.bedrock.llama2.chat.enabled` that you should set to `true` to enable support for Llama2.
88
-
89
41
Exporting environment variables in one way to set this configuration property.
90
42
91
43
[source,shell]
92
44
----
93
45
export SPRING_AI_BEDROCK_LLAMA2_CHAT_ENABLED=true
94
46
----
95
47
96
-
==== Sample Code
48
+
=== Chat Properties
49
+
50
+
The prefix `spring.ai.bedrock.aws` is the property prefix to configure the connection to AWS Bedrock.
51
+
52
+
[cols="3,3,3"]
53
+
|====
54
+
| Property | Description | Default
55
+
56
+
| spring.ai.bedrock.aws.region | AWS region to use. | us-east-1
The prefix `spring.ai.bedrock.llama2.chat` is the property prefix that configures the `ChatClient` implementation for Llama2.
63
+
64
+
[cols="2,5,1"]
65
+
|====
66
+
| Property | Description | Default
67
+
68
+
| spring.ai.bedrock.llama2.chat.enabled | Enable or disable support for Llama2 | false
69
+
| spring.ai.bedrock.llama2.chat.model | The model id to use (See Below) | meta.llama2-70b-chat-v1
70
+
| spring.ai.bedrock.llama2.chat.options.temperature | Controls the randomness of the output. Values can range over [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied, while a value closer to 0.0 will typically result in less surprising responses from the model. This value specifies default to be used by the backend while making the call to the model. | 0.7
71
+
| spring.ai.bedrock.llama2.chat.options.top-p | The maximum cumulative probability of tokens to consider when sampling. The model uses combined Top-k and nucleus sampling. Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP. | AWS Bedrock default
72
+
| spring.ai.bedrock.llama2.chat.options.max-gen-len | Specify the maximum number of tokens to use in the generated response. The model truncates the response once the generated text exceeds maxGenLen. | 300
73
+
|====
74
+
75
+
Look at the Spring AI enumeration, `Llama2ChatModel` for other model IDs. The other value supported is `meta.llama2-13b-chat-v1`.
76
+
77
+
Model ID values can also be found in the https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html[AWS Bedrock documentation for base model IDs].
78
+
79
+
=== Sample Code
97
80
98
81
This will create a `ChatClient` implementation that you can inject into your class.
99
82
@@ -126,36 +109,52 @@ public class ChatController {
126
109
}
127
110
----
128
111
129
-
=== Bedrock Properties
112
+
== Manual Configuration
130
113
131
-
The prefix `spring.ai.bedrock.aws` is the property prefix to configure the connection to AWS Bedrock.
114
+
Add the `spring-ai-bedrock` dependency to your project's Maven `pom.xml` file:
132
115
133
-
[cols="3,3,3"]
134
-
|====
135
-
| Property | Description | Default
116
+
[source,xml]
117
+
----
118
+
<dependency>
119
+
<groupId>org.springframework.ai</groupId>
120
+
<artifactId>spring-ai-bedrock</artifactId>
121
+
<version>0.8.0-SNAPSHOT</version>
122
+
</dependency>
123
+
----
136
124
137
-
| spring.ai.bedrock.aws.region | AWS region to use. | us-east-1
The prefix `spring.ai.bedrock.llama2.chat` is the property prefix that configures the `ChatClient` implementation for Llama2.
134
+
NOTE: Refer to the xref:getting-started.adoc#_dependency_management[Dependency Management] section to add Milestone and/or Snapshot Repositories to your build file.
144
135
145
-
[cols="2,5,1"]
146
-
|====
147
-
| Property | Description | Default
136
+
The link:./src/main/java/org/springframework/ai/bedrock/llama2/BedrockLlama2ChatClient.java[BedrockLlama2ChatClient] implements the `ChatClient` and `StreamingChatClient` and uses the `Llama2ChatBedrockApi` library to connect to the Bedrock Llama2 service.
148
137
149
-
| spring.ai.bedrock.llama2.chat.enabled | Enable or disable support for Llama2 | false
150
-
| spring.ai.bedrock.llama2.chat.model | The model id to use (See Below) | meta.llama2-70b-chat-v1
151
-
| spring.ai.bedrock.llama2.chat.options.temperature | Controls the randomness of the output. Values can range over [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied, while a value closer to 0.0 will typically result in less surprising responses from the model. This value specifies default to be used by the backend while making the call to the model. | 0.7
152
-
| spring.ai.bedrock.llama2.chat.options.top-p | The maximum cumulative probability of tokens to consider when sampling. The model uses combined Top-k and nucleus sampling. Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP. | AWS Bedrock default
153
-
| spring.ai.bedrock.llama2.chat.options.max-gen-len | Specify the maximum number of tokens to use in the generated response. The model truncates the response once the generated text exceeds maxGenLen. | 300
154
-
|====
138
+
Here is how to create and use a `BedrockLlama2ChatClient`:
155
139
156
-
Look at the Spring AI enumeration, `Llama2ChatModel` for other model IDs. The other value supported is `meta.llama2-13b-chat-v1`.
140
+
[source,java]
141
+
----
142
+
Llama2ChatBedrockApi api = new Llama2ChatBedrockApi(Llama2ChatModel.LLAMA2_70B_CHAT_V1.id(),
143
+
EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), new ObjectMapper());
157
144
158
-
Model ID values can also be found in the https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html[AWS Bedrock documentation for base model IDs].
145
+
BedrockLlama2ChatClient chatClient = new BedrockLlama2ChatClient(api,
146
+
BedrockLlama2ChatOptions.builder()
147
+
.withTemperature(0.5f)
148
+
.withMaxGenLen(100)
149
+
.withTopP(0.9f).build());
150
+
151
+
ChatResponse response = chatClient.call(
152
+
new Prompt("Generate the names of 5 famous pirates."));
153
+
154
+
// Or with streaming responses
155
+
Flux<ChatResponse> response = chatClient.stream(
156
+
new Prompt("Generate the names of 5 famous pirates."));
0 commit comments