Refactor Spring AI Bedrock options

- Refactor the options builder methods to remove `with` as the suffix
   - Update all the models under spring-ai-bedrock

 - Deprecate the existing methods
 - Update references and docs
This commit is contained in:
Ilayaperumal Gopinathan
2024-12-16 14:34:18 +00:00
committed by Mark Pollack
parent 58efee6d90
commit 65e7a1ddd9
43 changed files with 954 additions and 267 deletions

View File

@@ -124,7 +124,7 @@ ChatResponse response = chatModel.call(
new Prompt(
"Generate the names of 5 famous pirates.",
AnthropicChatOptions.builder()
.withTemperature(0.4)
.temperature(0.4)
.build()
));
----
@@ -217,11 +217,11 @@ AnthropicChatBedrockApi anthropicApi = new AnthropicChatBedrockApi(
BedrockAnthropicChatModel chatModel = new BedrockAnthropicChatModel(this.anthropicApi,
AnthropicChatOptions.builder()
.withTemperature(0.6)
.withTopK(10)
.withTopP(0.8)
.withMaxTokensToSample(100)
.withAnthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.temperature(0.6)
.topK(10)
.topP(0.8)
.maxTokensToSample(100)
.anthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.build());
ChatResponse response = this.chatModel.call(
@@ -251,9 +251,9 @@ AnthropicChatBedrockApi anthropicChatApi = new AnthropicChatBedrockApi(
AnthropicChatRequest request = AnthropicChatRequest
.builder(String.format(AnthropicChatBedrockApi.PROMPT_TEMPLATE, "Name 3 famous pirates"))
.withTemperature(0.8)
.withMaxTokensToSample(300)
.withTopK(10)
.temperature(0.8)
.maxTokensToSample(300)
.topK(10)
.build();
// Sync request

View File

@@ -121,7 +121,7 @@ ChatResponse response = chatModel.call(
new Prompt(
"Generate the names of 5 famous pirates.",
Anthropic3ChatOptions.builder()
.withTemperature(0.4)
.temperature(0.4)
.build()
));
----
@@ -258,11 +258,11 @@ Anthropic3ChatBedrockApi anthropicApi = new Anthropic3ChatBedrockApi(
BedrockAnthropic3ChatModel chatModel = new BedrockAnthropic3ChatModel(this.anthropicApi,
AnthropicChatOptions.builder()
.withTemperature(0.6)
.withTopK(10)
.withTopP(0.8)
.withMaxTokensToSample(100)
.withAnthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.temperature(0.6)
.topK(10)
.topP(0.8)
.maxTokensToSample(100)
.anthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.build());
ChatResponse response = this.chatModel.call(
@@ -288,9 +288,9 @@ Anthropic3ChatBedrockApi anthropicChatApi = new Anthropic3ChatBedrockApi(
AnthropicChatRequest request = AnthropicChatRequest
.builder(String.format(Anthropic3ChatBedrockApi.PROMPT_TEMPLATE, "Name 3 famous pirates"))
.withTemperature(0.8)
.withMaxTokensToSample(300)
.withTopK(10)
.temperature(0.8)
.maxTokensToSample(300)
.topK(10)
.build();
// Sync request

View File

@@ -117,7 +117,7 @@ ChatResponse response = chatModel.call(
new Prompt(
"Generate the names of 5 famous pirates.",
BedrockCohereChatOptions.builder()
.withTemperature(0.4)
.temperature(0.4)
.build()
));
----
@@ -208,10 +208,10 @@ CohereChatBedrockApi api = new CohereChatBedrockApi(CohereChatModel.COHERE_COMMA
BedrockCohereChatModel chatModel = new BedrockCohereChatModel(this.api,
BedrockCohereChatOptions.builder()
.withTemperature(0.6)
.withTopK(10)
.withTopP(0.5)
.withMaxTokens(678)
.temperature(0.6)
.topK(10)
.topP(0.5)
.maxTokens(678)
.build());
ChatResponse response = this.chatModel.call(
@@ -243,32 +243,32 @@ CohereChatBedrockApi cohereChatApi = new CohereChatBedrockApi(
var request = CohereChatRequest
.builder("What is the capital of Bulgaria and what is the size? What is the national anthem?")
.withStream(false)
.withTemperature(0.5)
.withTopP(0.8)
.withTopK(15)
.withMaxTokens(100)
.withStopSequences(List.of("END"))
.withReturnLikelihoods(CohereChatRequest.ReturnLikelihoods.ALL)
.withNumGenerations(3)
.withLogitBias(null)
.withTruncate(Truncate.NONE)
.stream(false)
.temperature(0.5)
.topP(0.8)
.topK(15)
.maxTokens(100)
.stopSequences(List.of("END"))
.returnLikelihoods(CohereChatRequest.ReturnLikelihoods.ALL)
.numGenerations(3)
.logitBias(null)
.truncate(Truncate.NONE)
.build();
CohereChatResponse response = this.cohereChatApi.chatCompletion(this.request);
var request = CohereChatRequest
.builder("What is the capital of Bulgaria and what is the size? What it the national anthem?")
.withStream(true)
.withTemperature(0.5)
.withTopP(0.8)
.withTopK(15)
.withMaxTokens(100)
.withStopSequences(List.of("END"))
.withReturnLikelihoods(CohereChatRequest.ReturnLikelihoods.ALL)
.withNumGenerations(3)
.withLogitBias(null)
.withTruncate(Truncate.NONE)
.stream(true)
.temperature(0.5)
.topP(0.8)
.topK(15)
.maxTokens(100)
.stopSequences(List.of("END"))
.returnLikelihoods(CohereChatRequest.ReturnLikelihoods.ALL)
.numGenerations(3)
.logitBias(null)
.truncate(Truncate.NONE)
.build();
Flux<CohereChatResponse.Generation> responseStream = this.cohereChatApi.chatCompletionStream(this.request);

View File

@@ -110,7 +110,7 @@ ChatResponse response = chatModel.call(
new Prompt(
"Generate the names of 5 famous pirates.",
BedrockAi21Jurassic2ChatOptions.builder()
.withTemperature(0.4)
.temperature(0.4)
.build()
));
----
@@ -196,9 +196,9 @@ Ai21Jurassic2ChatBedrockApi api = new Ai21Jurassic2ChatBedrockApi(Ai21Jurassic2C
BedrockAi21Jurassic2ChatModel chatModel = new BedrockAi21Jurassic2ChatModel(this.api,
BedrockAi21Jurassic2ChatOptions.builder()
.withTemperature(0.5)
.withMaxTokens(100)
.withTopP(0.9).build());
.temperature(0.5)
.maxTokens(100)
.topP(0.9).build());
ChatResponse response = this.chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
@@ -222,9 +222,9 @@ Ai21Jurassic2ChatBedrockApi jurassic2ChatApi = new Ai21Jurassic2ChatBedrockApi(
Duration.ofMillis(1000L));
Ai21Jurassic2ChatRequest request = Ai21Jurassic2ChatRequest.builder("Hello, my name is")
.withTemperature(0.9)
.withTopP(0.9)
.withMaxTokens(20)
.temperature(0.9)
.topP(0.9)
.maxTokens(20)
.build();
Ai21Jurassic2ChatResponse response = this.jurassic2ChatApi.chatCompletion(this.request);

View File

@@ -115,7 +115,7 @@ ChatResponse response = chatModel.call(
new Prompt(
"Generate the names of 5 famous pirates.",
BedrockLlamaChatOptions.builder()
.withTemperature(0.4)
.temperature(0.4)
.build()
));
----
@@ -206,9 +206,9 @@ LlamaChatBedrockApi api = new LlamaChatBedrockApi(LlamaChatModel.LLAMA2_70B_CHAT
BedrockLlamaChatModel chatModel = new BedrockLlamaChatModel(this.api,
BedrockLlamaChatOptions.builder()
.withTemperature(0.5)
.withMaxGenLen(100)
.withTopP(0.9).build());
.temperature(0.5)
.maxGenLen(100)
.topP(0.9).build());
ChatResponse response = this.chatModel.call(
new Prompt("Generate the names of 5 famous pirates."));
@@ -238,9 +238,9 @@ LlamaChatBedrockApi llamaChatApi = new LlamaChatBedrockApi(
Duration.ofMillis(1000L));
LlamaChatRequest request = LlamaChatRequest.builder("Hello, my name is")
.withTemperature(0.9)
.withTopP(0.9)
.withMaxGenLen(20)
.temperature(0.9)
.topP(0.9)
.maxGenLen(20)
.build();
LlamaChatResponse response = this.llamaChatApi.chatCompletion(this.request);

View File

@@ -113,7 +113,7 @@ ChatResponse response = chatModel.call(
new Prompt(
"Generate the names of 5 famous pirates.",
BedrockTitanChatOptions.builder()
.withTemperature(0.4)
.temperature(0.4)
.build()
));
----
@@ -205,9 +205,9 @@ TitanChatBedrockApi titanApi = new TitanChatBedrockApi(
BedrockTitanChatModel chatModel = new BedrockTitanChatModel(this.titanApi,
BedrockTitanChatOptions.builder()
.withTemperature(0.6)
.withTopP(0.8)
.withMaxTokenCount(100)
.temperature(0.6)
.topP(0.8)
.maxTokenCount(100)
.build());
ChatResponse response = this.chatModel.call(
@@ -236,10 +236,10 @@ TitanChatBedrockApi titanBedrockApi = new TitanChatBedrockApi(TitanChatCompletio
Region.US_EAST_1.id(), Duration.ofMillis(1000L));
TitanChatRequest titanChatRequest = TitanChatRequest.builder("Give me the names of 3 famous pirates?")
.withTemperature(0.5)
.withTopP(0.9)
.withMaxTokenCount(100)
.withStopSequences(List.of("|"))
.temperature(0.5)
.topP(0.9)
.maxTokenCount(100)
.stopSequences(List.of("|"))
.build();
TitanChatResponse response = this.titanBedrockApi.chatCompletion(this.titanChatRequest);