Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*
* @author Christian Tzolov
* @author Thomas Vitale
* @author Ilayaperumal Gopinathan
*/
@JsonInclude(Include.NON_NULL)
public class AnthropicChatOptions implements ChatOptions {
Expand Down Expand Up @@ -78,12 +79,12 @@ public static Builder builder() {
}

public static AnthropicChatOptions fromOptions(AnthropicChatOptions fromOptions) {
return builder().withTemperature(fromOptions.getTemperature())
.withMaxTokensToSample(fromOptions.getMaxTokensToSample())
.withTopK(fromOptions.getTopK())
.withTopP(fromOptions.getTopP())
.withStopSequences(fromOptions.getStopSequences())
.withAnthropicVersion(fromOptions.getAnthropicVersion())
return builder().temperature(fromOptions.getTemperature())
.maxTokensToSample(fromOptions.getMaxTokensToSample())
.topK(fromOptions.getTopK())
.topP(fromOptions.getTopP())
.stopSequences(fromOptions.getStopSequences())
.anthropicVersion(fromOptions.getAnthropicVersion())
.build();
}

Expand Down Expand Up @@ -177,31 +178,85 @@ public static class Builder {

private final AnthropicChatOptions options = new AnthropicChatOptions();

public Builder temperature(Double temperature) {
this.options.setTemperature(temperature);
return this;
}

public Builder maxTokensToSample(Integer maxTokensToSample) {
this.options.setMaxTokensToSample(maxTokensToSample);
return this;
}

public Builder topK(Integer topK) {
this.options.setTopK(topK);
return this;
}

public Builder topP(Double topP) {
this.options.setTopP(topP);
return this;
}

public Builder stopSequences(List<String> stopSequences) {
this.options.setStopSequences(stopSequences);
return this;
}

public Builder anthropicVersion(String anthropicVersion) {
this.options.setAnthropicVersion(anthropicVersion);
return this;
}

/**
* @deprecated use {@link #temperature(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTemperature(Double temperature) {
this.options.setTemperature(temperature);
return this;
}

/**
* @deprecated use {@link #maxTokensToSample(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withMaxTokensToSample(Integer maxTokensToSample) {
this.options.setMaxTokensToSample(maxTokensToSample);
return this;
}

/**
* @deprecated use {@link #topK(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopK(Integer topK) {
this.options.setTopK(topK);
return this;
}

/**
* @deprecated use {@link #topP(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopP(Double topP) {
this.options.setTopP(topP);
return this;
}

/**
* @deprecated use {@link #stopSequences(List)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withStopSequences(List<String> stopSequences) {
this.options.setStopSequences(stopSequences);
return this;
}

/**
* @deprecated use {@link #anthropicVersion(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withAnthropicVersion(String anthropicVersion) {
this.options.setAnthropicVersion(anthropicVersion);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public class BedrockAnthropicChatModel implements ChatModel, StreamingChatModel
public BedrockAnthropicChatModel(AnthropicChatBedrockApi chatApi) {
this(chatApi,
AnthropicChatOptions.builder()
.withTemperature(0.8)
.withMaxTokensToSample(500)
.withTopK(10)
.withAnthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.temperature(0.8)
.maxTokensToSample(500)
.topK(10)
.anthropicVersion(AnthropicChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @author Christian Tzolov
* @author Thomas Vitale
* @author Wei Jiang
* @author Ilayaperumal Gopinathan
* @since 0.8.0
*/
// @formatter:off
Expand Down Expand Up @@ -215,31 +216,85 @@ private Builder(String prompt) {
this.prompt = prompt;
}

public Builder temperature(Double temperature) {
this.temperature = temperature;
return this;
}

public Builder maxTokensToSample(Integer maxTokensToSample) {
this.maxTokensToSample = maxTokensToSample;
return this;
}

public Builder topK(Integer topK) {
this.topK = topK;
return this;
}

public Builder topP(Double tpoP) {
this.topP = tpoP;
return this;
}

public Builder stopSequences(List<String> stopSequences) {
this.stopSequences = stopSequences;
return this;
}

public Builder anthropicVersion(String anthropicVersion) {
this.anthropicVersion = anthropicVersion;
return this;
}

/**
* @deprecated use {@link #temperature( Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTemperature(Double temperature) {
this.temperature = temperature;
return this;
}

/**
* @deprecated use {@link #maxTokensToSample( Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withMaxTokensToSample(Integer maxTokensToSample) {
this.maxTokensToSample = maxTokensToSample;
return this;
}

/**
* @deprecated use {@link #topK( Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopK(Integer topK) {
this.topK = topK;
return this;
}

/**
* @deprecated use {@link #topP( Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopP(Double tpoP) {
this.topP = tpoP;
return this;
}

/**
* @deprecated use {@link #stopSequences( List)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withStopSequences(List<String> stopSequences) {
this.stopSequences = stopSequences;
return this;
}

/**
* @deprecated use {@link #anthropicVersion( String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withAnthropicVersion(String anthropicVersion) {
this.anthropicVersion = anthropicVersion;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public static Builder builder() {
* @return a new {@link Anthropic3ChatOptions}
*/
public static Anthropic3ChatOptions fromOptions(Anthropic3ChatOptions fromOptions) {
return builder().withTemperature(fromOptions.getTemperature())
.withMaxTokens(fromOptions.getMaxTokens())
.withTopK(fromOptions.getTopK())
.withTopP(fromOptions.getTopP())
.withStopSequences(fromOptions.getStopSequences())
.withAnthropicVersion(fromOptions.getAnthropicVersion())
return builder().temperature(fromOptions.getTemperature())
.maxTokens(fromOptions.getMaxTokens())
.topK(fromOptions.getTopK())
.topP(fromOptions.getTopP())
.stopSequences(fromOptions.getStopSequences())
.anthropicVersion(fromOptions.getAnthropicVersion())
.build();
}

Expand Down Expand Up @@ -256,7 +256,7 @@ private Builder() {
* @param temperature the temperature
* @return this {@link Builder} instance
*/
public Builder withTemperature(Double temperature) {
public Builder temperature(Double temperature) {
this.options.setTemperature(temperature);
return this;
}
Expand All @@ -266,7 +266,7 @@ public Builder withTemperature(Double temperature) {
* @param maxTokens the maximum number of tokens
* @return this {@link Builder} instance
*/
public Builder withMaxTokens(Integer maxTokens) {
public Builder maxTokens(Integer maxTokens) {
this.options.setMaxTokens(maxTokens);
return this;
}
Expand All @@ -276,7 +276,7 @@ public Builder withMaxTokens(Integer maxTokens) {
* @param topK the top k
* @return this {@link Builder} instance
*/
public Builder withTopK(Integer topK) {
public Builder topK(Integer topK) {
this.options.setTopK(topK);
return this;
}
Expand All @@ -286,7 +286,7 @@ public Builder withTopK(Integer topK) {
* @param topP the top p
* @return this {@link Builder} instance
*/
public Builder withTopP(Double topP) {
public Builder topP(Double topP) {
this.options.setTopP(topP);
return this;
}
Expand All @@ -296,7 +296,7 @@ public Builder withTopP(Double topP) {
* @param stopSequences the stop sequences
* @return this {@link Builder} instance
*/
public Builder withStopSequences(List<String> stopSequences) {
public Builder stopSequences(List<String> stopSequences) {
this.options.setStopSequences(stopSequences);
return this;
}
Expand All @@ -306,6 +306,60 @@ public Builder withStopSequences(List<String> stopSequences) {
* @param anthropicVersion the version of the generative to use
* @return this {@link Builder} instance
*/
public Builder anthropicVersion(String anthropicVersion) {
this.options.setAnthropicVersion(anthropicVersion);
return this;
}

/**
* @deprecated use {@link #temperature(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTemperature(Double temperature) {
this.options.setTemperature(temperature);
return this;
}

/**
* @deprecated use {@link #maxTokens(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withMaxTokens(Integer maxTokens) {
this.options.setMaxTokens(maxTokens);
return this;
}

/**
* @deprecated use {@link #topK(Integer)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopK(Integer topK) {
this.options.setTopK(topK);
return this;
}

/**
* @deprecated use {@link #topP(Double)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withTopP(Double topP) {
this.options.setTopP(topP);
return this;
}

/**
* @deprecated use {@link #stopSequences(List)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withStopSequences(List<String> stopSequences) {
this.options.setStopSequences(stopSequences);
return this;
}

/**
* @deprecated use {@link #anthropicVersion(String)} instead.
*/
@Deprecated(forRemoval = true, since = "1.0.0-M5")
public Builder withAnthropicVersion(String anthropicVersion) {
this.options.setAnthropicVersion(anthropicVersion);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public class BedrockAnthropic3ChatModel implements ChatModel, StreamingChatModel
public BedrockAnthropic3ChatModel(Anthropic3ChatBedrockApi chatApi) {
this(chatApi,
Anthropic3ChatOptions.builder()
.withTemperature(0.8)
.withMaxTokens(500)
.withTopK(10)
.withAnthropicVersion(Anthropic3ChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.temperature(0.8)
.maxTokens(500)
.topK(10)
.anthropicVersion(Anthropic3ChatBedrockApi.DEFAULT_ANTHROPIC_VERSION)
.build());
}

Expand Down Expand Up @@ -138,7 +138,7 @@ protected Usage extractUsage(AnthropicChatResponse response) {
AnthropicChatRequest createRequest(Prompt prompt) {

AnthropicChatRequest request = AnthropicChatRequest.builder(toAnthropicMessages(prompt))
.withSystem(toAnthropicSystemContext(prompt))
.system(toAnthropicSystemContext(prompt))
.build();

if (this.defaultOptions != null) {
Expand Down
Loading
Loading