Use Double instead of Float for portable ChatOptions
This change updates the type of portable chat options from Float to Double. Affected options include: - frequencyPenalty - presencePenalty - temperature - topP The motivation for this change is to simplify coding. In Java, Float values require an "f" suffix (e.g., 0.5f), while Double values don't need any suffix. This makes Double easier to type and reduces potential errors from forgetting the "f" suffix. APIs, tests, and documentation have been updated to reflect this change. Fixes gh-712 Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
This commit is contained in:
committed by
Mark Pollack
parent
40714c984d
commit
4b123a7516
@@ -39,7 +39,7 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
* responses from the generative. This value specifies default to be used by the backend while making the call to
|
||||
* the generative.
|
||||
*/
|
||||
private @JsonProperty("temperature") Float temperature;
|
||||
private @JsonProperty("temperature") Double temperature;
|
||||
|
||||
/**
|
||||
* Specify the maximum number of tokens to use in the generated response. Note that the models may stop before
|
||||
@@ -57,7 +57,7 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
* The maximum cumulative probability of tokens to consider when sampling. The generative uses combined Top-k and
|
||||
* nucleus sampling. Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP.
|
||||
*/
|
||||
private @JsonProperty("top_p") Float topP;
|
||||
private @JsonProperty("top_p") Double topP;
|
||||
|
||||
/**
|
||||
* Configure up to four sequences that the generative recognizes. After a stop sequence, the generative stops
|
||||
@@ -79,7 +79,7 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
|
||||
private final AnthropicChatOptions options = new AnthropicChatOptions();
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.options.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.options.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
@@ -116,11 +116,11 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@@ -153,11 +153,11 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -186,13 +186,13 @@ public class AnthropicChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BedrockAnthropicChatModel implements ChatModel, StreamingChatModel
|
||||
public BedrockAnthropicChatModel(AnthropicChatBedrockApi chatApi) {
|
||||
this(chatApi,
|
||||
AnthropicChatOptions.builder()
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokensToSample(500)
|
||||
.withTopK(10)
|
||||
.withAnthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @author Wei Jiang
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -139,10 +140,10 @@ public class AnthropicChatBedrockApi extends
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record AnthropicChatRequest(
|
||||
@JsonProperty("prompt") String prompt,
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("temperature") Double temperature,
|
||||
@JsonProperty("max_tokens_to_sample") Integer maxTokensToSample,
|
||||
@JsonProperty("top_k") Integer topK,
|
||||
@JsonProperty("top_p") Float topP,
|
||||
@JsonProperty("top_p") Double topP,
|
||||
@JsonProperty("stop_sequences") List<String> stopSequences,
|
||||
@JsonProperty("anthropic_version") String anthropicVersion) {
|
||||
|
||||
@@ -152,10 +153,10 @@ public class AnthropicChatBedrockApi extends
|
||||
|
||||
public static class Builder {
|
||||
private final String prompt;
|
||||
private Float temperature;// = 0.7f;
|
||||
private Double temperature;// = 0.7;
|
||||
private Integer maxTokensToSample;// = 500;
|
||||
private Integer topK;// = 10;
|
||||
private Float topP;
|
||||
private Double topP;
|
||||
private List<String> stopSequences;
|
||||
private String anthropicVersion;
|
||||
|
||||
@@ -163,7 +164,7 @@ public class AnthropicChatBedrockApi extends
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
@@ -178,7 +179,7 @@ public class AnthropicChatBedrockApi extends
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float tpoP) {
|
||||
public Builder withTopP(Double tpoP) {
|
||||
this.topP = tpoP;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
* responses from the generative. This value specifies default to be used by the backend while making the call to
|
||||
* the generative.
|
||||
*/
|
||||
private @JsonProperty("temperature") Float temperature;
|
||||
private @JsonProperty("temperature") Double temperature;
|
||||
|
||||
/**
|
||||
* Specify the maximum number of tokens to use in the generated response. Note that the models may stop before
|
||||
@@ -56,7 +56,7 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
* The maximum cumulative probability of tokens to consider when sampling. The generative uses combined Top-k and
|
||||
* nucleus sampling. Nucleus sampling considers the smallest set of tokens whose probability sum is at least topP.
|
||||
*/
|
||||
private @JsonProperty("top_p") Float topP;
|
||||
private @JsonProperty("top_p") Double topP;
|
||||
|
||||
/**
|
||||
* Configure up to four sequences that the generative recognizes. After a stop sequence, the generative stops
|
||||
@@ -78,7 +78,7 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
|
||||
private final Anthropic3ChatOptions options = new Anthropic3ChatOptions();
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.options.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.options.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
@@ -115,11 +115,11 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@@ -142,11 +142,11 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -175,13 +175,13 @@ public class Anthropic3ChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ public class BedrockAnthropic3ChatModel implements ChatModel, StreamingChatModel
|
||||
public BedrockAnthropic3ChatModel(Anthropic3ChatBedrockApi chatApi) {
|
||||
this(chatApi,
|
||||
Anthropic3ChatOptions.builder()
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokens(500)
|
||||
.withTopK(10)
|
||||
.withAnthropicVersion(Anthropic3ChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.util.List;
|
||||
*
|
||||
* @author Ben Middleton
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @author Wei Jiang
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@@ -146,10 +147,10 @@ public class Anthropic3ChatBedrockApi extends
|
||||
public record AnthropicChatRequest(
|
||||
@JsonProperty("messages") List<ChatCompletionMessage> messages,
|
||||
@JsonProperty("system") String system,
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("temperature") Double temperature,
|
||||
@JsonProperty("max_tokens") Integer maxTokens,
|
||||
@JsonProperty("top_k") Integer topK,
|
||||
@JsonProperty("top_p") Float topP,
|
||||
@JsonProperty("top_p") Double topP,
|
||||
@JsonProperty("stop_sequences") List<String> stopSequences,
|
||||
@JsonProperty("anthropic_version") String anthropicVersion) {
|
||||
|
||||
@@ -160,10 +161,10 @@ public class Anthropic3ChatBedrockApi extends
|
||||
public static class Builder {
|
||||
private final List<ChatCompletionMessage> messages;
|
||||
private String system;
|
||||
private Float temperature;// = 0.7f;
|
||||
private Double temperature;// = 0.7;
|
||||
private Integer maxTokens;// = 500;
|
||||
private Integer topK;// = 10;
|
||||
private Float topP;
|
||||
private Double topP;
|
||||
private List<String> stopSequences;
|
||||
private String anthropicVersion;
|
||||
|
||||
@@ -175,7 +176,7 @@ public class Anthropic3ChatBedrockApi extends
|
||||
this.system = system;
|
||||
return this;
|
||||
}
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
@@ -190,7 +191,7 @@ public class Anthropic3ChatBedrockApi extends
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float tpoP) {
|
||||
public Builder withTopP(Double tpoP) {
|
||||
this.topP = tpoP;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -40,13 +40,13 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
* (optional) Use a lower value to decrease randomness in the response. Defaults to
|
||||
* 0.7.
|
||||
*/
|
||||
@JsonProperty("temperature") Float temperature;
|
||||
@JsonProperty("temperature") Double temperature;
|
||||
/**
|
||||
* (optional) The maximum cumulative probability of tokens to consider when sampling.
|
||||
* The generative uses combined Top-k and nucleus sampling. Nucleus sampling considers
|
||||
* the smallest set of tokens whose probability sum is at least topP.
|
||||
*/
|
||||
@JsonProperty("p") Float topP;
|
||||
@JsonProperty("p") Double topP;
|
||||
/**
|
||||
* (optional) Specify the number of token choices the generative uses to generate the
|
||||
* next token.
|
||||
@@ -89,12 +89,12 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
|
||||
private final BedrockCohereChatOptions options = new BedrockCohereChatOptions();
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.options.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.options.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
@@ -141,20 +141,20 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -225,13 +225,13 @@ public class BedrockCohereChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
|
||||
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-cohere.html
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @author Wei Jiang
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -130,8 +131,8 @@ public class CohereChatBedrockApi extends
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record CohereChatRequest(
|
||||
@JsonProperty("prompt") String prompt,
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("p") Float topP,
|
||||
@JsonProperty("temperature") Double temperature,
|
||||
@JsonProperty("p") Double topP,
|
||||
@JsonProperty("k") Integer topK,
|
||||
@JsonProperty("max_tokens") Integer maxTokens,
|
||||
@JsonProperty("stop_sequences") List<String> stopSequences,
|
||||
@@ -204,8 +205,8 @@ public class CohereChatBedrockApi extends
|
||||
*/
|
||||
public static class Builder {
|
||||
private final String prompt;
|
||||
private Float temperature;
|
||||
private Float topP;
|
||||
private Double temperature;
|
||||
private Double topP;
|
||||
private Integer topK;
|
||||
private Integer maxTokens;
|
||||
private List<String> stopSequences;
|
||||
@@ -219,12 +220,12 @@ public class CohereChatBedrockApi extends
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ public class BedrockAi21Jurassic2ChatModel implements ChatModel {
|
||||
public BedrockAi21Jurassic2ChatModel(Ai21Jurassic2ChatBedrockApi chatApi) {
|
||||
this(chatApi,
|
||||
BedrockAi21Jurassic2ChatOptions.builder()
|
||||
.withTemperature(0.8f)
|
||||
.withTopP(0.9f)
|
||||
.withTemperature(0.8)
|
||||
.withTopP(0.9)
|
||||
.withMaxTokens(100)
|
||||
.build());
|
||||
}
|
||||
|
||||
@@ -61,13 +61,13 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
* Modifies the distribution from which tokens are sampled.
|
||||
*/
|
||||
@JsonProperty("temperature")
|
||||
private Float temperature;
|
||||
private Double temperature;
|
||||
|
||||
/**
|
||||
* Sample tokens from the corresponding top percentile of probability mass.
|
||||
*/
|
||||
@JsonProperty("topP")
|
||||
private Float topP;
|
||||
private Double topP;
|
||||
|
||||
/**
|
||||
* Return the top-K (topKReturn) alternative tokens.
|
||||
@@ -171,7 +171,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
* @return The temperature.
|
||||
*/
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
* Sets the temperature for modifying the token sampling distribution.
|
||||
* @param temperature The temperature.
|
||||
*/
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
* @return The topP parameter.
|
||||
*/
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return topP;
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
* mass.
|
||||
* @param topP The topP parameter.
|
||||
*/
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -238,12 +238,12 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return getFrequencyPenaltyOptions() != null ? getFrequencyPenaltyOptions().scale() : null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setFrequencyPenalty(Float frequencyPenalty) {
|
||||
public void setFrequencyPenalty(Double frequencyPenalty) {
|
||||
if (frequencyPenalty != null) {
|
||||
setFrequencyPenaltyOptions(Penalty.builder().scale(frequencyPenalty).build());
|
||||
}
|
||||
@@ -267,12 +267,12 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return getPresencePenaltyOptions() != null ? getPresencePenaltyOptions().scale() : null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public void setPresencePenalty(Float presencePenalty) {
|
||||
public void setPresencePenalty(Double presencePenalty) {
|
||||
if (presencePenalty != null) {
|
||||
setPresencePenaltyOptions(Penalty.builder().scale(presencePenalty).build());
|
||||
}
|
||||
@@ -344,12 +344,12 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
request.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
request.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
@@ -389,7 +389,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
* Penalty object for frequency, presence, and count penalties.
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record Penalty(@JsonProperty("scale") Float scale, @JsonProperty("applyToNumbers") Boolean applyToNumbers,
|
||||
public record Penalty(@JsonProperty("scale") Double scale, @JsonProperty("applyToNumbers") Boolean applyToNumbers,
|
||||
@JsonProperty("applyToPunctuations") Boolean applyToPunctuations,
|
||||
@JsonProperty("applyToStopwords") Boolean applyToStopwords,
|
||||
@JsonProperty("applyToWhitespaces") Boolean applyToWhitespaces,
|
||||
@@ -401,7 +401,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private Float scale;
|
||||
private Double scale;
|
||||
|
||||
// can't keep it null due to modelOptionsUtils#mapToClass convert null to
|
||||
// false
|
||||
@@ -415,7 +415,7 @@ public class BedrockAi21Jurassic2ChatOptions implements ChatOptions {
|
||||
|
||||
private Boolean applyToEmojis = true;
|
||||
|
||||
public Builder scale(Float scale) {
|
||||
public Builder scale(Double scale) {
|
||||
this.scale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import software.amazon.awssdk.regions.Region;
|
||||
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-jurassic2.html
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @author Wei Jiang
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -132,8 +133,8 @@ public class Ai21Jurassic2ChatBedrockApi extends
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record Ai21Jurassic2ChatRequest(
|
||||
@JsonProperty("prompt") String prompt,
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("topP") Float topP,
|
||||
@JsonProperty("temperature") Double temperature,
|
||||
@JsonProperty("topP") Double topP,
|
||||
@JsonProperty("maxTokens") Integer maxTokens,
|
||||
@JsonProperty("stopSequences") List<String> stopSequences,
|
||||
@JsonProperty("countPenalty") IntegerScalePenalty countPenalty,
|
||||
@@ -198,8 +199,8 @@ public class Ai21Jurassic2ChatBedrockApi extends
|
||||
}
|
||||
public static class Builder {
|
||||
private String prompt;
|
||||
private Float temperature;
|
||||
private Float topP;
|
||||
private Double temperature;
|
||||
private Double topP;
|
||||
private Integer maxTokens;
|
||||
private List<String> stopSequences;
|
||||
private IntegerScalePenalty countPenalty;
|
||||
@@ -210,12 +211,12 @@ public class Ai21Jurassic2ChatBedrockApi extends
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ public class BedrockLlamaChatModel implements ChatModel, StreamingChatModel {
|
||||
private final BedrockLlamaChatOptions defaultOptions;
|
||||
|
||||
public BedrockLlamaChatModel(LlamaChatBedrockApi chatApi) {
|
||||
this(chatApi,
|
||||
BedrockLlamaChatOptions.builder().withTemperature(0.8f).withTopP(0.9f).withMaxGenLen(100).build());
|
||||
this(chatApi, BedrockLlamaChatOptions.builder().withTemperature(0.8).withTopP(0.9).withMaxGenLen(100).build());
|
||||
}
|
||||
|
||||
public BedrockLlamaChatModel(LlamaChatBedrockApi chatApi, BedrockLlamaChatOptions options) {
|
||||
|
||||
@@ -35,13 +35,13 @@ public class BedrockLlamaChatOptions implements ChatOptions {
|
||||
* The temperature value controls the randomness of the generated text. Use a lower
|
||||
* value to decrease randomness in the response.
|
||||
*/
|
||||
private @JsonProperty("temperature") Float temperature;
|
||||
private @JsonProperty("temperature") Double temperature;
|
||||
|
||||
/**
|
||||
* The topP value controls the diversity of the generated text. Use a lower value to
|
||||
* ignore less probable options. Set to 0 or 1.0 to disable.
|
||||
*/
|
||||
private @JsonProperty("top_p") Float topP;
|
||||
private @JsonProperty("top_p") Double topP;
|
||||
|
||||
/**
|
||||
* The maximum length of the generated text.
|
||||
@@ -56,12 +56,12 @@ public class BedrockLlamaChatOptions implements ChatOptions {
|
||||
|
||||
private BedrockLlamaChatOptions options = new BedrockLlamaChatOptions();
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.options.setTemperature(temperature);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.options.setTopP(topP);
|
||||
return this;
|
||||
}
|
||||
@@ -78,20 +78,20 @@ public class BedrockLlamaChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return this.temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return this.topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ public class BedrockLlamaChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.time.Duration;
|
||||
* https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-meta.html
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @author Wei Jiang
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -119,8 +120,8 @@ public class LlamaChatBedrockApi extends
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record LlamaChatRequest(
|
||||
@JsonProperty("prompt") String prompt,
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("top_p") Float topP,
|
||||
@JsonProperty("temperature") Double temperature,
|
||||
@JsonProperty("top_p") Double topP,
|
||||
@JsonProperty("max_gen_len") Integer maxGenLen) {
|
||||
|
||||
/**
|
||||
@@ -134,20 +135,20 @@ public class LlamaChatBedrockApi extends
|
||||
|
||||
public static class Builder {
|
||||
private String prompt;
|
||||
private Float temperature;
|
||||
private Float topP;
|
||||
private Double temperature;
|
||||
private Double topP;
|
||||
private Integer maxGenLen;
|
||||
|
||||
public Builder(String prompt) {
|
||||
this.prompt = prompt;
|
||||
}
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BedrockTitanChatModel implements ChatModel, StreamingChatModel {
|
||||
private final BedrockTitanChatOptions defaultOptions;
|
||||
|
||||
public BedrockTitanChatModel(TitanChatBedrockApi chatApi) {
|
||||
this(chatApi, BedrockTitanChatOptions.builder().withTemperature(0.8f).build());
|
||||
this(chatApi, BedrockTitanChatOptions.builder().withTemperature(0.8).build());
|
||||
}
|
||||
|
||||
public BedrockTitanChatModel(TitanChatBedrockApi chatApi, BedrockTitanChatOptions defaultOptions) {
|
||||
|
||||
@@ -37,12 +37,12 @@ public class BedrockTitanChatOptions implements ChatOptions {
|
||||
/**
|
||||
* The temperature value controls the randomness of the generated text.
|
||||
*/
|
||||
private @JsonProperty("temperature") Float temperature;
|
||||
private @JsonProperty("temperature") Double temperature;
|
||||
|
||||
/**
|
||||
* The topP value controls the diversity of the generated text. Use a lower value to ignore less probable options.
|
||||
*/
|
||||
private @JsonProperty("topP") Float topP;
|
||||
private @JsonProperty("topP") Double topP;
|
||||
|
||||
/**
|
||||
* Maximum number of tokens to generate.
|
||||
@@ -63,12 +63,12 @@ public class BedrockTitanChatOptions implements ChatOptions {
|
||||
|
||||
private BedrockTitanChatOptions options = new BedrockTitanChatOptions();
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.options.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.options.topP = topP;
|
||||
return this;
|
||||
}
|
||||
@@ -90,20 +90,20 @@ public class BedrockTitanChatOptions implements ChatOptions {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTemperature() {
|
||||
public Double getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
public void setTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getTopP() {
|
||||
public Double getTopP() {
|
||||
return topP;
|
||||
}
|
||||
|
||||
public void setTopP(Float topP) {
|
||||
public void setTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
}
|
||||
|
||||
@@ -143,13 +143,13 @@ public class BedrockTitanChatOptions implements ChatOptions {
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getFrequencyPenalty() {
|
||||
public Double getFrequencyPenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public Float getPresencePenalty() {
|
||||
public Double getPresencePenalty() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.ai.model.ChatModelDescription;
|
||||
* https://docs.aws.amazon.com/bedrock/latest/userguide/titan-text-models.html
|
||||
*
|
||||
* @author Christian Tzolov
|
||||
* @author Thomas Vitale
|
||||
* @author Wei Jiang
|
||||
* @since 0.8.0
|
||||
*/
|
||||
@@ -134,8 +135,8 @@ public class TitanChatBedrockApi extends
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
public record TextGenerationConfig(
|
||||
@JsonProperty("temperature") Float temperature,
|
||||
@JsonProperty("topP") Float topP,
|
||||
@JsonProperty("temperature") Double temperature,
|
||||
@JsonProperty("topP") Double topP,
|
||||
@JsonProperty("maxTokenCount") Integer maxTokenCount,
|
||||
@JsonProperty("stopSequences") List<String> stopSequences) {
|
||||
}
|
||||
@@ -151,8 +152,8 @@ public class TitanChatBedrockApi extends
|
||||
|
||||
public static class Builder {
|
||||
private final String inputText;
|
||||
private Float temperature;
|
||||
private Float topP;
|
||||
private Double temperature;
|
||||
private Double topP;
|
||||
private Integer maxTokenCount;
|
||||
private List<String> stopSequences;
|
||||
|
||||
@@ -160,12 +161,12 @@ public class TitanChatBedrockApi extends
|
||||
this.inputText = inputText;
|
||||
}
|
||||
|
||||
public Builder withTemperature(Float temperature) {
|
||||
public Builder withTemperature(Double temperature) {
|
||||
this.temperature = temperature;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withTopP(Float topP) {
|
||||
public Builder withTopP(Double topP) {
|
||||
this.topP = topP;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -40,9 +40,9 @@ public class BedrockAnthropicCreateRequestTests {
|
||||
|
||||
var client = new BedrockAnthropicChatModel(anthropicChatApi,
|
||||
AnthropicChatOptions.builder()
|
||||
.withTemperature(66.6f)
|
||||
.withTemperature(66.6)
|
||||
.withTopK(66)
|
||||
.withTopP(0.66f)
|
||||
.withTopP(0.66)
|
||||
.withMaxTokensToSample(666)
|
||||
.withAnthropicVersion("X.Y.Z")
|
||||
.withStopSequences(List.of("stop1", "stop2"))
|
||||
@@ -51,17 +51,17 @@ public class BedrockAnthropicCreateRequestTests {
|
||||
var request = client.createRequest(new Prompt("Test message content"));
|
||||
|
||||
assertThat(request.prompt()).isNotEmpty();
|
||||
assertThat(request.temperature()).isEqualTo(66.6f);
|
||||
assertThat(request.temperature()).isEqualTo(66.6);
|
||||
assertThat(request.topK()).isEqualTo(66);
|
||||
assertThat(request.topP()).isEqualTo(0.66f);
|
||||
assertThat(request.topP()).isEqualTo(0.66);
|
||||
assertThat(request.maxTokensToSample()).isEqualTo(666);
|
||||
assertThat(request.anthropicVersion()).isEqualTo("X.Y.Z");
|
||||
assertThat(request.stopSequences()).containsExactly("stop1", "stop2");
|
||||
|
||||
request = client.createRequest(new Prompt("Test message content",
|
||||
AnthropicChatOptions.builder()
|
||||
.withTemperature(99.9f)
|
||||
.withTopP(0.99f)
|
||||
.withTemperature(99.9)
|
||||
.withTopP(0.99)
|
||||
.withMaxTokensToSample(999)
|
||||
.withAnthropicVersion("zzz")
|
||||
.withStopSequences(List.of("stop3", "stop4"))
|
||||
@@ -70,9 +70,9 @@ public class BedrockAnthropicCreateRequestTests {
|
||||
));
|
||||
|
||||
assertThat(request.prompt()).isNotEmpty();
|
||||
assertThat(request.temperature()).isEqualTo(99.9f);
|
||||
assertThat(request.temperature()).isEqualTo(99.9);
|
||||
assertThat(request.topK()).as("unchanged from the default options").isEqualTo(66);
|
||||
assertThat(request.topP()).isEqualTo(0.99f);
|
||||
assertThat(request.topP()).isEqualTo(0.99);
|
||||
assertThat(request.maxTokensToSample()).isEqualTo(999);
|
||||
assertThat(request.anthropicVersion()).isEqualTo("zzz");
|
||||
assertThat(request.stopSequences()).containsExactly("stop3", "stop4");
|
||||
|
||||
@@ -52,7 +52,7 @@ public class AnthropicChatBedrockApiIT {
|
||||
|
||||
AnthropicChatRequest request = AnthropicChatRequest
|
||||
.builder(String.format(AnthropicChatBedrockApi.PROMPT_TEMPLATE, "Name 3 famous pirates"))
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokensToSample(300)
|
||||
.withTopK(10)
|
||||
.build();
|
||||
@@ -75,7 +75,7 @@ public class AnthropicChatBedrockApiIT {
|
||||
|
||||
AnthropicChatRequest request = AnthropicChatRequest
|
||||
.builder(String.format(AnthropicChatBedrockApi.PROMPT_TEMPLATE, "Name 3 famous pirates"))
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokensToSample(300)
|
||||
.withTopK(10)
|
||||
.withStopSequences(List.of("\n\nHuman:"))
|
||||
|
||||
@@ -39,9 +39,9 @@ public class BedrockAnthropic3CreateRequestTests {
|
||||
|
||||
var client = new BedrockAnthropic3ChatModel(anthropicChatApi,
|
||||
Anthropic3ChatOptions.builder()
|
||||
.withTemperature(66.6f)
|
||||
.withTemperature(66.6)
|
||||
.withTopK(66)
|
||||
.withTopP(0.66f)
|
||||
.withTopP(0.66)
|
||||
.withMaxTokens(666)
|
||||
.withAnthropicVersion("X.Y.Z")
|
||||
.withStopSequences(List.of("stop1", "stop2"))
|
||||
@@ -50,17 +50,17 @@ public class BedrockAnthropic3CreateRequestTests {
|
||||
var request = client.createRequest(new Prompt("Test message content"));
|
||||
|
||||
assertThat(request.messages()).isNotEmpty();
|
||||
assertThat(request.temperature()).isEqualTo(66.6f);
|
||||
assertThat(request.temperature()).isEqualTo(66.6);
|
||||
assertThat(request.topK()).isEqualTo(66);
|
||||
assertThat(request.topP()).isEqualTo(0.66f);
|
||||
assertThat(request.topP()).isEqualTo(0.66);
|
||||
assertThat(request.maxTokens()).isEqualTo(666);
|
||||
assertThat(request.anthropicVersion()).isEqualTo("X.Y.Z");
|
||||
assertThat(request.stopSequences()).containsExactly("stop1", "stop2");
|
||||
|
||||
request = client.createRequest(new Prompt("Test message content",
|
||||
Anthropic3ChatOptions.builder()
|
||||
.withTemperature(99.9f)
|
||||
.withTopP(0.99f)
|
||||
.withTemperature(99.9)
|
||||
.withTopP(0.99)
|
||||
.withMaxTokens(999)
|
||||
.withAnthropicVersion("zzz")
|
||||
.withStopSequences(List.of("stop3", "stop4"))
|
||||
@@ -69,9 +69,9 @@ public class BedrockAnthropic3CreateRequestTests {
|
||||
));
|
||||
|
||||
assertThat(request.messages()).isNotEmpty();
|
||||
assertThat(request.temperature()).isEqualTo(99.9f);
|
||||
assertThat(request.temperature()).isEqualTo(99.9);
|
||||
assertThat(request.topK()).as("unchanged from the default options").isEqualTo(66);
|
||||
assertThat(request.topP()).isEqualTo(0.99f);
|
||||
assertThat(request.topP()).isEqualTo(0.99);
|
||||
assertThat(request.maxTokens()).isEqualTo(999);
|
||||
assertThat(request.anthropicVersion()).isEqualTo("zzz");
|
||||
assertThat(request.stopSequences()).containsExactly("stop3", "stop4");
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Anthropic3ChatBedrockApiIT {
|
||||
MediaContent anthropicMessage = new MediaContent("Name 3 famous pirates");
|
||||
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage(List.of(anthropicMessage), Role.USER);
|
||||
AnthropicChatRequest request = AnthropicChatRequest.builder(List.of(chatCompletionMessage))
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokens(300)
|
||||
.withTopK(10)
|
||||
.withAnthropicVersion(DEFAULT_ANTHROPIC_VERSION)
|
||||
@@ -97,7 +97,7 @@ public class Anthropic3ChatBedrockApiIT {
|
||||
AnthropicChatRequest request = AnthropicChatRequest
|
||||
.builder(List.of(chatCompletionInitialMessage, chatCompletionAssistantMessage,
|
||||
chatCompletionFollowupMessage))
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokens(400)
|
||||
.withTopK(10)
|
||||
.withAnthropicVersion(DEFAULT_ANTHROPIC_VERSION)
|
||||
@@ -123,7 +123,7 @@ public class Anthropic3ChatBedrockApiIT {
|
||||
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage(List.of(anthropicMessage), Role.USER);
|
||||
|
||||
AnthropicChatRequest request = AnthropicChatRequest.builder(List.of(chatCompletionMessage))
|
||||
.withTemperature(0.8f)
|
||||
.withTemperature(0.8)
|
||||
.withMaxTokens(300)
|
||||
.withTopK(10)
|
||||
.withAnthropicVersion(DEFAULT_ANTHROPIC_VERSION)
|
||||
|
||||
@@ -47,9 +47,9 @@ public class BedrockCohereChatCreateRequestTests {
|
||||
|
||||
var client = new BedrockCohereChatModel(chatApi,
|
||||
BedrockCohereChatOptions.builder()
|
||||
.withTemperature(66.6f)
|
||||
.withTemperature(66.6)
|
||||
.withTopK(66)
|
||||
.withTopP(0.66f)
|
||||
.withTopP(0.66)
|
||||
.withMaxTokens(678)
|
||||
.withStopSequences(List.of("stop1", "stop2"))
|
||||
.withReturnLikelihoods(ReturnLikelihoods.ALL)
|
||||
@@ -63,9 +63,9 @@ public class BedrockCohereChatCreateRequestTests {
|
||||
assertThat(request.prompt()).isNotEmpty();
|
||||
assertThat(request.stream()).isTrue();
|
||||
|
||||
assertThat(request.temperature()).isEqualTo(66.6f);
|
||||
assertThat(request.temperature()).isEqualTo(66.6);
|
||||
assertThat(request.topK()).isEqualTo(66);
|
||||
assertThat(request.topP()).isEqualTo(0.66f);
|
||||
assertThat(request.topP()).isEqualTo(0.66);
|
||||
assertThat(request.maxTokens()).isEqualTo(678);
|
||||
assertThat(request.stopSequences()).containsExactly("stop1", "stop2");
|
||||
assertThat(request.returnLikelihoods()).isEqualTo(ReturnLikelihoods.ALL);
|
||||
@@ -75,9 +75,9 @@ public class BedrockCohereChatCreateRequestTests {
|
||||
|
||||
request = client.createRequest(new Prompt("Test message content",
|
||||
BedrockCohereChatOptions.builder()
|
||||
.withTemperature(99.9f)
|
||||
.withTemperature(99.9)
|
||||
.withTopK(99)
|
||||
.withTopP(0.99f)
|
||||
.withTopP(0.99)
|
||||
.withMaxTokens(888)
|
||||
.withStopSequences(List.of("stop3", "stop4"))
|
||||
.withReturnLikelihoods(ReturnLikelihoods.GENERATION)
|
||||
@@ -92,9 +92,9 @@ public class BedrockCohereChatCreateRequestTests {
|
||||
assertThat(request.prompt()).isNotEmpty();
|
||||
assertThat(request.stream()).isFalse();
|
||||
|
||||
assertThat(request.temperature()).isEqualTo(99.9f);
|
||||
assertThat(request.temperature()).isEqualTo(99.9);
|
||||
assertThat(request.topK()).isEqualTo(99);
|
||||
assertThat(request.topP()).isEqualTo(0.99f);
|
||||
assertThat(request.topP()).isEqualTo(0.99);
|
||||
assertThat(request.maxTokens()).isEqualTo(888);
|
||||
assertThat(request.stopSequences()).containsExactly("stop3", "stop4");
|
||||
assertThat(request.returnLikelihoods()).isEqualTo(ReturnLikelihoods.GENERATION);
|
||||
|
||||
@@ -49,13 +49,13 @@ public class CohereChatBedrockApiIT {
|
||||
public void requestBuilder() {
|
||||
|
||||
CohereChatRequest request1 = new CohereChatRequest(
|
||||
"What is the capital of Bulgaria and what is the size? What it the national anthem?", 0.5f, 0.9f, 15,
|
||||
40, List.of("END"), CohereChatRequest.ReturnLikelihoods.ALL, false, 1, null, Truncate.NONE);
|
||||
"What is the capital of Bulgaria and what is the size? What it the national anthem?", 0.5, 0.9, 15, 40,
|
||||
List.of("END"), CohereChatRequest.ReturnLikelihoods.ALL, false, 1, null, Truncate.NONE);
|
||||
|
||||
var request2 = CohereChatRequest
|
||||
.builder("What is the capital of Bulgaria and what is the size? What it the national anthem?")
|
||||
.withTemperature(0.5f)
|
||||
.withTopP(0.9f)
|
||||
.withTemperature(0.5)
|
||||
.withTopP(0.9)
|
||||
.withTopK(15)
|
||||
.withMaxTokens(40)
|
||||
.withStopSequences(List.of("END"))
|
||||
@@ -75,8 +75,8 @@ public class CohereChatBedrockApiIT {
|
||||
var request = CohereChatRequest
|
||||
.builder("What is the capital of Bulgaria and what is the size? What it the national anthem?")
|
||||
.withStream(false)
|
||||
.withTemperature(0.5f)
|
||||
.withTopP(0.8f)
|
||||
.withTemperature(0.5)
|
||||
.withTopP(0.8)
|
||||
.withTopK(15)
|
||||
.withMaxTokens(100)
|
||||
.withStopSequences(List.of("END"))
|
||||
@@ -100,8 +100,8 @@ public class CohereChatBedrockApiIT {
|
||||
var request = CohereChatRequest
|
||||
.builder("What is the capital of Bulgaria and what is the size? What it the national anthem?")
|
||||
.withStream(true)
|
||||
.withTemperature(0.5f)
|
||||
.withTopP(0.8f)
|
||||
.withTemperature(0.5)
|
||||
.withTopP(0.8)
|
||||
.withTopK(15)
|
||||
.withMaxTokens(100)
|
||||
.withStopSequences(List.of("END"))
|
||||
|
||||
@@ -157,9 +157,9 @@ class BedrockAi21Jurassic2ChatModelIT {
|
||||
Ai21Jurassic2ChatBedrockApi jurassic2ChatBedrockApi) {
|
||||
return new BedrockAi21Jurassic2ChatModel(jurassic2ChatBedrockApi,
|
||||
BedrockAi21Jurassic2ChatOptions.builder()
|
||||
.withTemperature(0.5f)
|
||||
.withTemperature(0.5)
|
||||
.withMaxTokens(100)
|
||||
.withTopP(0.9f)
|
||||
.withTopP(0.9)
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ public class Ai21Jurassic2ChatBedrockApiIT {
|
||||
|
||||
@Test
|
||||
public void chatCompletion() {
|
||||
Ai21Jurassic2ChatRequest request = new Ai21Jurassic2ChatRequest("Give me the names of 3 famous pirates?", 0.9f,
|
||||
0.9f, 100, null, // List.of("END"),
|
||||
Ai21Jurassic2ChatRequest request = new Ai21Jurassic2ChatRequest("Give me the names of 3 famous pirates?", 0.9,
|
||||
0.9, 100, null, // List.of("END"),
|
||||
new Ai21Jurassic2ChatRequest.IntegerScalePenalty(1, true, true, true, true, true),
|
||||
new Ai21Jurassic2ChatRequest.FloatScalePenalty(0.5f, true, true, true, true, true),
|
||||
new Ai21Jurassic2ChatRequest.IntegerScalePenalty(1, true, true, true, true, true));
|
||||
|
||||
@@ -208,7 +208,7 @@ class BedrockLlamaChatModelIT {
|
||||
@Bean
|
||||
public BedrockLlamaChatModel llamaChatModel(LlamaChatBedrockApi llamaApi) {
|
||||
return new BedrockLlamaChatModel(llamaApi,
|
||||
BedrockLlamaChatOptions.builder().withTemperature(0.5f).withMaxGenLen(100).withTopP(0.9f).build());
|
||||
BedrockLlamaChatOptions.builder().withTemperature(0.5).withMaxGenLen(100).withTopP(0.9).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BedrockLlamaCreateRequestTests {
|
||||
public void createRequestWithChatOptions() {
|
||||
|
||||
var client = new BedrockLlamaChatModel(api,
|
||||
BedrockLlamaChatOptions.builder().withTemperature(66.6f).withMaxGenLen(666).withTopP(0.66f).build());
|
||||
BedrockLlamaChatOptions.builder().withTemperature(66.6).withMaxGenLen(666).withTopP(0.66).build());
|
||||
|
||||
var request = client.createRequest(new Prompt("Test message content"));
|
||||
|
||||
@@ -56,7 +56,7 @@ public class BedrockLlamaCreateRequestTests {
|
||||
assertThat(request.maxGenLen()).isEqualTo(666);
|
||||
|
||||
request = client.createRequest(new Prompt("Test message content",
|
||||
BedrockLlamaChatOptions.builder().withTemperature(99.9f).withMaxGenLen(999).withTopP(0.99f).build()));
|
||||
BedrockLlamaChatOptions.builder().withTemperature(99.9).withMaxGenLen(999).withTopP(0.99).build()));
|
||||
|
||||
assertThat(request.prompt()).isNotEmpty();
|
||||
assertThat(request.temperature()).isEqualTo(99.9f);
|
||||
|
||||
@@ -48,8 +48,8 @@ public class LlamaChatBedrockApiIT {
|
||||
public void chatCompletion() {
|
||||
|
||||
LlamaChatRequest request = LlamaChatRequest.builder("Hello, my name is")
|
||||
.withTemperature(0.9f)
|
||||
.withTopP(0.9f)
|
||||
.withTemperature(0.9)
|
||||
.withTopP(0.9)
|
||||
.withMaxGenLen(20)
|
||||
.build();
|
||||
|
||||
@@ -67,7 +67,7 @@ public class LlamaChatBedrockApiIT {
|
||||
@Test
|
||||
public void chatCompletionStream() {
|
||||
|
||||
LlamaChatRequest request = new LlamaChatRequest("Hello, my name is", 0.9f, 0.9f, 20);
|
||||
LlamaChatRequest request = new LlamaChatRequest("Hello, my name is", 0.9, 0.9, 20);
|
||||
Flux<LlamaChatResponse> responseStream = llamaChatApi.chatCompletionStream(request);
|
||||
List<LlamaChatResponse> responses = responseStream.collectList().block();
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ public class BedrockTitanChatModelCreateRequestTests {
|
||||
|
||||
var model = new BedrockTitanChatModel(api,
|
||||
BedrockTitanChatOptions.builder()
|
||||
.withTemperature(66.6f)
|
||||
.withTopP(0.66f)
|
||||
.withTemperature(66.6)
|
||||
.withTopP(0.66)
|
||||
.withMaxTokenCount(666)
|
||||
.withStopSequences(List.of("stop1", "stop2"))
|
||||
.build());
|
||||
@@ -52,15 +52,15 @@ public class BedrockTitanChatModelCreateRequestTests {
|
||||
var request = model.createRequest(new Prompt("Test message content"));
|
||||
|
||||
assertThat(request.inputText()).isNotEmpty();
|
||||
assertThat(request.textGenerationConfig().temperature()).isEqualTo(66.6f);
|
||||
assertThat(request.textGenerationConfig().topP()).isEqualTo(0.66f);
|
||||
assertThat(request.textGenerationConfig().temperature()).isEqualTo(66.6);
|
||||
assertThat(request.textGenerationConfig().topP()).isEqualTo(0.66);
|
||||
assertThat(request.textGenerationConfig().maxTokenCount()).isEqualTo(666);
|
||||
assertThat(request.textGenerationConfig().stopSequences()).containsExactly("stop1", "stop2");
|
||||
|
||||
request = model.createRequest(new Prompt("Test message content",
|
||||
BedrockTitanChatOptions.builder()
|
||||
.withTemperature(99.9f)
|
||||
.withTopP(0.99f)
|
||||
.withTemperature(99.9)
|
||||
.withTopP(0.99)
|
||||
.withMaxTokenCount(999)
|
||||
.withStopSequences(List.of("stop3", "stop4"))
|
||||
.build()
|
||||
@@ -68,8 +68,8 @@ public class BedrockTitanChatModelCreateRequestTests {
|
||||
));
|
||||
|
||||
assertThat(request.inputText()).isNotEmpty();
|
||||
assertThat(request.textGenerationConfig().temperature()).isEqualTo(99.9f);
|
||||
assertThat(request.textGenerationConfig().topP()).isEqualTo(0.99f);
|
||||
assertThat(request.textGenerationConfig().temperature()).isEqualTo(99.9);
|
||||
assertThat(request.textGenerationConfig().topP()).isEqualTo(0.99);
|
||||
assertThat(request.textGenerationConfig().maxTokenCount()).isEqualTo(999);
|
||||
assertThat(request.textGenerationConfig().stopSequences()).containsExactly("stop3", "stop4");
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ public class TitanChatBedrockApiIT {
|
||||
Duration.ofMinutes(2));
|
||||
|
||||
TitanChatRequest titanChatRequest = TitanChatRequest.builder("Give me the names of 3 famous pirates?")
|
||||
.withTemperature(0.5f)
|
||||
.withTopP(0.9f)
|
||||
.withTemperature(0.5)
|
||||
.withTopP(0.9)
|
||||
.withMaxTokenCount(100)
|
||||
.withStopSequences(List.of("|"))
|
||||
.build();
|
||||
|
||||
Reference in New Issue
Block a user