software.amazon.awssdk.services.bedrockruntime.model.ConverseRequest Maven / Gradle / Ivy
Show all versions of bedrockruntime Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.bedrockruntime.model;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.document.Document;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class ConverseRequest extends BedrockRuntimeRequest implements
ToCopyableBuilder {
private static final SdkField MODEL_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("modelId").getter(getter(ConverseRequest::modelId)).setter(setter(Builder::modelId))
.traits(LocationTrait.builder().location(MarshallLocation.PATH).locationName("modelId").build()).build();
private static final SdkField> MESSAGES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("messages")
.getter(getter(ConverseRequest::messages))
.setter(setter(Builder::messages))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("messages").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(Message::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> SYSTEM_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("system")
.getter(getter(ConverseRequest::system))
.setter(setter(Builder::system))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("system").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(SystemContentBlock::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField INFERENCE_CONFIG_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("inferenceConfig")
.getter(getter(ConverseRequest::inferenceConfig)).setter(setter(Builder::inferenceConfig))
.constructor(InferenceConfiguration::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("inferenceConfig").build()).build();
private static final SdkField TOOL_CONFIG_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("toolConfig")
.getter(getter(ConverseRequest::toolConfig)).setter(setter(Builder::toolConfig))
.constructor(ToolConfiguration::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("toolConfig").build()).build();
private static final SdkField GUARDRAIL_CONFIG_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("guardrailConfig")
.getter(getter(ConverseRequest::guardrailConfig)).setter(setter(Builder::guardrailConfig))
.constructor(GuardrailConfiguration::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("guardrailConfig").build()).build();
private static final SdkField ADDITIONAL_MODEL_REQUEST_FIELDS_FIELD = SdkField
. builder(MarshallingType.DOCUMENT)
.memberName("additionalModelRequestFields")
.getter(getter(ConverseRequest::additionalModelRequestFields))
.setter(setter(Builder::additionalModelRequestFields))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("additionalModelRequestFields")
.build()).build();
private static final SdkField> ADDITIONAL_MODEL_RESPONSE_FIELD_PATHS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("additionalModelResponseFieldPaths")
.getter(getter(ConverseRequest::additionalModelResponseFieldPaths))
.setter(setter(Builder::additionalModelResponseFieldPaths))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("additionalModelResponseFieldPaths")
.build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(MODEL_ID_FIELD,
MESSAGES_FIELD, SYSTEM_FIELD, INFERENCE_CONFIG_FIELD, TOOL_CONFIG_FIELD, GUARDRAIL_CONFIG_FIELD,
ADDITIONAL_MODEL_REQUEST_FIELDS_FIELD, ADDITIONAL_MODEL_RESPONSE_FIELD_PATHS_FIELD));
private final String modelId;
private final List messages;
private final List system;
private final InferenceConfiguration inferenceConfig;
private final ToolConfiguration toolConfig;
private final GuardrailConfiguration guardrailConfig;
private final Document additionalModelRequestFields;
private final List additionalModelResponseFieldPaths;
private ConverseRequest(BuilderImpl builder) {
super(builder);
this.modelId = builder.modelId;
this.messages = builder.messages;
this.system = builder.system;
this.inferenceConfig = builder.inferenceConfig;
this.toolConfig = builder.toolConfig;
this.guardrailConfig = builder.guardrailConfig;
this.additionalModelRequestFields = builder.additionalModelRequestFields;
this.additionalModelResponseFieldPaths = builder.additionalModelResponseFieldPaths;
}
/**
*
* The identifier for the model that you want to call.
*
*
* The modelId
to provide depends on the type of model or throughput that you use:
*
*
* -
*
* If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see Amazon Bedrock base
* model IDs (on-demand throughput) in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference profile
* IDs, see Supported Regions
* and models for cross-region inference in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see Run inference using a Provisioned
* Throughput in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use a custom model, first purchase Provisioned Throughput for it. Then specify the ARN of the resulting
* provisioned model. For more information, see Use a custom model in
* Amazon Bedrock in the Amazon Bedrock User Guide.
*
*
*
*
* The Converse API doesn't support imported
* models.
*
*
* @return The identifier for the model that you want to call.
*
* The modelId
to provide depends on the type of model or throughput that you use:
*
*
* -
*
* If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see Amazon Bedrock
* base model IDs (on-demand throughput) in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference
* profile IDs, see Supported
* Regions and models for cross-region inference in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see
* Run inference using a
* Provisioned Throughput in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use a custom model, first purchase Provisioned Throughput for it. Then specify the ARN of the
* resulting provisioned model. For more information, see Use a custom
* model in Amazon Bedrock in the Amazon Bedrock User Guide.
*
*
*
*
* The Converse API doesn't support imported models.
*/
public final String modelId() {
return modelId;
}
/**
* For responses, this returns true if the service returned a value for the Messages property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasMessages() {
return messages != null && !(messages instanceof SdkAutoConstructList);
}
/**
*
* The messages that you want to send to the model.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasMessages} method.
*
*
* @return The messages that you want to send to the model.
*/
public final List messages() {
return messages;
}
/**
* For responses, this returns true if the service returned a value for the System property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasSystem() {
return system != null && !(system instanceof SdkAutoConstructList);
}
/**
*
* A system prompt to pass to the model.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasSystem} method.
*
*
* @return A system prompt to pass to the model.
*/
public final List system() {
return system;
}
/**
*
* Inference parameters to pass to the model. Converse
supports a base set of inference parameters. If
* you need to pass additional parameters that the model supports, use the additionalModelRequestFields
* request field.
*
*
* @return Inference parameters to pass to the model. Converse
supports a base set of inference
* parameters. If you need to pass additional parameters that the model supports, use the
* additionalModelRequestFields
request field.
*/
public final InferenceConfiguration inferenceConfig() {
return inferenceConfig;
}
/**
*
* Configuration information for the tools that the model can use when generating a response.
*
*
*
* This field is only supported by Anthropic Claude 3, Cohere Command R, Cohere Command R+, and Mistral Large
* models.
*
*
*
* @return Configuration information for the tools that the model can use when generating a response.
*
* This field is only supported by Anthropic Claude 3, Cohere Command R, Cohere Command R+, and Mistral
* Large models.
*
*/
public final ToolConfiguration toolConfig() {
return toolConfig;
}
/**
*
* Configuration information for a guardrail that you want to use in the request.
*
*
* @return Configuration information for a guardrail that you want to use in the request.
*/
public final GuardrailConfiguration guardrailConfig() {
return guardrailConfig;
}
/**
*
* Additional inference parameters that the model supports, beyond the base set of inference parameters that
* Converse
supports in the inferenceConfig
field. For more information, see Model parameters.
*
*
* @return Additional inference parameters that the model supports, beyond the base set of inference parameters that
* Converse
supports in the inferenceConfig
field. For more information, see Model parameters.
*/
public final Document additionalModelRequestFields() {
return additionalModelRequestFields;
}
/**
* For responses, this returns true if the service returned a value for the AdditionalModelResponseFieldPaths
* property. This DOES NOT check that the value is non-empty (for which, you should check the {@code isEmpty()}
* method on the property). This is useful because the SDK will never return a null collection or map, but you may
* need to differentiate between the service returning nothing (or null) and the service returning an empty
* collection or map. For requests, this returns true if a value for the property was specified in the request
* builder, and false if a value was not specified.
*/
public final boolean hasAdditionalModelResponseFieldPaths() {
return additionalModelResponseFieldPaths != null && !(additionalModelResponseFieldPaths instanceof SdkAutoConstructList);
}
/**
*
* Additional model parameters field paths to return in the response. Converse
returns the requested
* fields as a JSON Pointer object in the additionalModelResponseFields
field. The following is example
* JSON for additionalModelResponseFieldPaths
.
*
*
* [ "/stop_sequence" ]
*
*
* For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF) documentation.
*
*
* Converse
rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a
* 400
error code. if the JSON Pointer is valid, but the requested field is not in the model response,
* it is ignored by Converse
.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasAdditionalModelResponseFieldPaths}
* method.
*
*
* @return Additional model parameters field paths to return in the response. Converse
returns the
* requested fields as a JSON Pointer object in the additionalModelResponseFields
field. The
* following is example JSON for additionalModelResponseFieldPaths
.
*
* [ "/stop_sequence" ]
*
*
* For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF)
* documentation.
*
*
* Converse
rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a
* 400
error code. if the JSON Pointer is valid, but the requested field is not in the model
* response, it is ignored by Converse
.
*/
public final List additionalModelResponseFieldPaths() {
return additionalModelResponseFieldPaths;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(modelId());
hashCode = 31 * hashCode + Objects.hashCode(hasMessages() ? messages() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasSystem() ? system() : null);
hashCode = 31 * hashCode + Objects.hashCode(inferenceConfig());
hashCode = 31 * hashCode + Objects.hashCode(toolConfig());
hashCode = 31 * hashCode + Objects.hashCode(guardrailConfig());
hashCode = 31 * hashCode + Objects.hashCode(additionalModelRequestFields());
hashCode = 31 * hashCode
+ Objects.hashCode(hasAdditionalModelResponseFieldPaths() ? additionalModelResponseFieldPaths() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ConverseRequest)) {
return false;
}
ConverseRequest other = (ConverseRequest) obj;
return Objects.equals(modelId(), other.modelId()) && hasMessages() == other.hasMessages()
&& Objects.equals(messages(), other.messages()) && hasSystem() == other.hasSystem()
&& Objects.equals(system(), other.system()) && Objects.equals(inferenceConfig(), other.inferenceConfig())
&& Objects.equals(toolConfig(), other.toolConfig()) && Objects.equals(guardrailConfig(), other.guardrailConfig())
&& Objects.equals(additionalModelRequestFields(), other.additionalModelRequestFields())
&& hasAdditionalModelResponseFieldPaths() == other.hasAdditionalModelResponseFieldPaths()
&& Objects.equals(additionalModelResponseFieldPaths(), other.additionalModelResponseFieldPaths());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString
.builder("ConverseRequest")
.add("ModelId", modelId())
.add("Messages", hasMessages() ? messages() : null)
.add("System", hasSystem() ? system() : null)
.add("InferenceConfig", inferenceConfig())
.add("ToolConfig", toolConfig())
.add("GuardrailConfig", guardrailConfig())
.add("AdditionalModelRequestFields", additionalModelRequestFields())
.add("AdditionalModelResponseFieldPaths",
hasAdditionalModelResponseFieldPaths() ? additionalModelResponseFieldPaths() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "modelId":
return Optional.ofNullable(clazz.cast(modelId()));
case "messages":
return Optional.ofNullable(clazz.cast(messages()));
case "system":
return Optional.ofNullable(clazz.cast(system()));
case "inferenceConfig":
return Optional.ofNullable(clazz.cast(inferenceConfig()));
case "toolConfig":
return Optional.ofNullable(clazz.cast(toolConfig()));
case "guardrailConfig":
return Optional.ofNullable(clazz.cast(guardrailConfig()));
case "additionalModelRequestFields":
return Optional.ofNullable(clazz.cast(additionalModelRequestFields()));
case "additionalModelResponseFieldPaths":
return Optional.ofNullable(clazz.cast(additionalModelResponseFieldPaths()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function
*
* The modelId
to provide depends on the type of model or throughput that you use:
*
*
* -
*
* If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see
* Amazon
* Bedrock base model IDs (on-demand throughput) in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference
* profile IDs, see Supported Regions and models for cross-region inference in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information,
* see Run inference
* using a Provisioned Throughput in the Amazon Bedrock User Guide.
*
*
* -
*
* If you use a custom model, first purchase Provisioned Throughput for it. Then specify the ARN of the
* resulting provisioned model. For more information, see Use a custom
* model in Amazon Bedrock in the Amazon Bedrock User Guide.
*
*
*
*
* The Converse API doesn't support imported models.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder modelId(String modelId);
/**
*
* The messages that you want to send to the model.
*
*
* @param messages
* The messages that you want to send to the model.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder messages(Collection messages);
/**
*
* The messages that you want to send to the model.
*
*
* @param messages
* The messages that you want to send to the model.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder messages(Message... messages);
/**
*
* The messages that you want to send to the model.
*
* This is a convenience method that creates an instance of the
* {@link software.amazon.awssdk.services.bedrockruntime.model.Message.Builder} avoiding the need to create one
* manually via {@link software.amazon.awssdk.services.bedrockruntime.model.Message#builder()}.
*
*
* When the {@link Consumer} completes,
* {@link software.amazon.awssdk.services.bedrockruntime.model.Message.Builder#build()} is called immediately
* and its result is passed to {@link #messages(List)}.
*
* @param messages
* a consumer that will call methods on
* {@link software.amazon.awssdk.services.bedrockruntime.model.Message.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #messages(java.util.Collection)
*/
Builder messages(Consumer... messages);
/**
*
* A system prompt to pass to the model.
*
*
* @param system
* A system prompt to pass to the model.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder system(Collection system);
/**
*
* A system prompt to pass to the model.
*
*
* @param system
* A system prompt to pass to the model.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder system(SystemContentBlock... system);
/**
*
* A system prompt to pass to the model.
*
* This is a convenience method that creates an instance of the
* {@link software.amazon.awssdk.services.bedrockruntime.model.SystemContentBlock.Builder} avoiding the need to
* create one manually via
* {@link software.amazon.awssdk.services.bedrockruntime.model.SystemContentBlock#builder()}.
*
*
* When the {@link Consumer} completes,
* {@link software.amazon.awssdk.services.bedrockruntime.model.SystemContentBlock.Builder#build()} is called
* immediately and its result is passed to {@link #system(List)}.
*
* @param system
* a consumer that will call methods on
* {@link software.amazon.awssdk.services.bedrockruntime.model.SystemContentBlock.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #system(java.util.Collection)
*/
Builder system(Consumer... system);
/**
*
* Inference parameters to pass to the model. Converse
supports a base set of inference parameters.
* If you need to pass additional parameters that the model supports, use the
* additionalModelRequestFields
request field.
*
*
* @param inferenceConfig
* Inference parameters to pass to the model. Converse
supports a base set of inference
* parameters. If you need to pass additional parameters that the model supports, use the
* additionalModelRequestFields
request field.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder inferenceConfig(InferenceConfiguration inferenceConfig);
/**
*
* Inference parameters to pass to the model. Converse
supports a base set of inference parameters.
* If you need to pass additional parameters that the model supports, use the
* additionalModelRequestFields
request field.
*
* This is a convenience method that creates an instance of the {@link InferenceConfiguration.Builder} avoiding
* the need to create one manually via {@link InferenceConfiguration#builder()}.
*
*
* When the {@link Consumer} completes, {@link InferenceConfiguration.Builder#build()} is called immediately and
* its result is passed to {@link #inferenceConfig(InferenceConfiguration)}.
*
* @param inferenceConfig
* a consumer that will call methods on {@link InferenceConfiguration.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #inferenceConfig(InferenceConfiguration)
*/
default Builder inferenceConfig(Consumer inferenceConfig) {
return inferenceConfig(InferenceConfiguration.builder().applyMutation(inferenceConfig).build());
}
/**
*
* Configuration information for the tools that the model can use when generating a response.
*
*
*
* This field is only supported by Anthropic Claude 3, Cohere Command R, Cohere Command R+, and Mistral Large
* models.
*
*
*
* @param toolConfig
* Configuration information for the tools that the model can use when generating a response.
*
* This field is only supported by Anthropic Claude 3, Cohere Command R, Cohere Command R+, and Mistral
* Large models.
*
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder toolConfig(ToolConfiguration toolConfig);
/**
*
* Configuration information for the tools that the model can use when generating a response.
*
*
*
* This field is only supported by Anthropic Claude 3, Cohere Command R, Cohere Command R+, and Mistral Large
* models.
*
* This is a convenience method that creates an instance of the {@link ToolConfiguration.Builder}
* avoiding the need to create one manually via {@link ToolConfiguration#builder()}.
*
*
* When the {@link Consumer} completes, {@link ToolConfiguration.Builder#build()} is called immediately and its
* result is passed to {@link #toolConfig(ToolConfiguration)}.
*
* @param toolConfig
* a consumer that will call methods on {@link ToolConfiguration.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #toolConfig(ToolConfiguration)
*/
default Builder toolConfig(Consumer toolConfig) {
return toolConfig(ToolConfiguration.builder().applyMutation(toolConfig).build());
}
/**
*
* Configuration information for a guardrail that you want to use in the request.
*
*
* @param guardrailConfig
* Configuration information for a guardrail that you want to use in the request.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder guardrailConfig(GuardrailConfiguration guardrailConfig);
/**
*
* Configuration information for a guardrail that you want to use in the request.
*
* This is a convenience method that creates an instance of the {@link GuardrailConfiguration.Builder} avoiding
* the need to create one manually via {@link GuardrailConfiguration#builder()}.
*
*
* When the {@link Consumer} completes, {@link GuardrailConfiguration.Builder#build()} is called immediately and
* its result is passed to {@link #guardrailConfig(GuardrailConfiguration)}.
*
* @param guardrailConfig
* a consumer that will call methods on {@link GuardrailConfiguration.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #guardrailConfig(GuardrailConfiguration)
*/
default Builder guardrailConfig(Consumer guardrailConfig) {
return guardrailConfig(GuardrailConfiguration.builder().applyMutation(guardrailConfig).build());
}
/**
*
* Additional inference parameters that the model supports, beyond the base set of inference parameters that
* Converse
supports in the inferenceConfig
field. For more information, see Model parameters.
*
*
* @param additionalModelRequestFields
* Additional inference parameters that the model supports, beyond the base set of inference parameters
* that Converse
supports in the inferenceConfig
field. For more information,
* see Model
* parameters.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder additionalModelRequestFields(Document additionalModelRequestFields);
/**
*
* Additional model parameters field paths to return in the response. Converse
returns the
* requested fields as a JSON Pointer object in the additionalModelResponseFields
field. The
* following is example JSON for additionalModelResponseFieldPaths
.
*
*
* [ "/stop_sequence" ]
*
*
* For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF)
* documentation.
*
*
* Converse
rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a
* 400
error code. if the JSON Pointer is valid, but the requested field is not in the model
* response, it is ignored by Converse
.
*
*
* @param additionalModelResponseFieldPaths
* Additional model parameters field paths to return in the response. Converse
returns the
* requested fields as a JSON Pointer object in the additionalModelResponseFields
field. The
* following is example JSON for additionalModelResponseFieldPaths
.
*
* [ "/stop_sequence" ]
*
*
* For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF)
* documentation.
*
*
* Converse
rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a
* 400
error code. if the JSON Pointer is valid, but the requested field is not in the model
* response, it is ignored by Converse
.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder additionalModelResponseFieldPaths(Collection additionalModelResponseFieldPaths);
/**
*
* Additional model parameters field paths to return in the response. Converse
returns the
* requested fields as a JSON Pointer object in the additionalModelResponseFields
field. The
* following is example JSON for additionalModelResponseFieldPaths
.
*
*
* [ "/stop_sequence" ]
*
*
* For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF)
* documentation.
*
*
* Converse
rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a
* 400
error code. if the JSON Pointer is valid, but the requested field is not in the model
* response, it is ignored by Converse
.
*
*
* @param additionalModelResponseFieldPaths
* Additional model parameters field paths to return in the response. Converse
returns the
* requested fields as a JSON Pointer object in the additionalModelResponseFields
field. The
* following is example JSON for additionalModelResponseFieldPaths
.
*
* [ "/stop_sequence" ]
*
*
* For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF)
* documentation.
*
*
* Converse
rejects an empty JSON Pointer or incorrectly structured JSON Pointer with a
* 400
error code. if the JSON Pointer is valid, but the requested field is not in the model
* response, it is ignored by Converse
.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder additionalModelResponseFieldPaths(String... additionalModelResponseFieldPaths);
@Override
Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration);
@Override
Builder overrideConfiguration(Consumer builderConsumer);
}
static final class BuilderImpl extends BedrockRuntimeRequest.BuilderImpl implements Builder {
private String modelId;
private List messages = DefaultSdkAutoConstructList.getInstance();
private List system = DefaultSdkAutoConstructList.getInstance();
private InferenceConfiguration inferenceConfig;
private ToolConfiguration toolConfig;
private GuardrailConfiguration guardrailConfig;
private Document additionalModelRequestFields;
private List additionalModelResponseFieldPaths = DefaultSdkAutoConstructList.getInstance();
private BuilderImpl() {
}
private BuilderImpl(ConverseRequest model) {
super(model);
modelId(model.modelId);
messages(model.messages);
system(model.system);
inferenceConfig(model.inferenceConfig);
toolConfig(model.toolConfig);
guardrailConfig(model.guardrailConfig);
additionalModelRequestFields(model.additionalModelRequestFields);
additionalModelResponseFieldPaths(model.additionalModelResponseFieldPaths);
}
public final String getModelId() {
return modelId;
}
public final void setModelId(String modelId) {
this.modelId = modelId;
}
@Override
public final Builder modelId(String modelId) {
this.modelId = modelId;
return this;
}
public final List getMessages() {
List result = MessagesCopier.copyToBuilder(this.messages);
if (result instanceof SdkAutoConstructList) {
return null;
}
return result;
}
public final void setMessages(Collection messages) {
this.messages = MessagesCopier.copyFromBuilder(messages);
}
@Override
public final Builder messages(Collection messages) {
this.messages = MessagesCopier.copy(messages);
return this;
}
@Override
@SafeVarargs
public final Builder messages(Message... messages) {
messages(Arrays.asList(messages));
return this;
}
@Override
@SafeVarargs
public final Builder messages(Consumer... messages) {
messages(Stream.of(messages).map(c -> Message.builder().applyMutation(c).build()).collect(Collectors.toList()));
return this;
}
public final List getSystem() {
List result = SystemContentBlocksCopier.copyToBuilder(this.system);
if (result instanceof SdkAutoConstructList) {
return null;
}
return result;
}
public final void setSystem(Collection system) {
this.system = SystemContentBlocksCopier.copyFromBuilder(system);
}
@Override
public final Builder system(Collection system) {
this.system = SystemContentBlocksCopier.copy(system);
return this;
}
@Override
@SafeVarargs
public final Builder system(SystemContentBlock... system) {
system(Arrays.asList(system));
return this;
}
@Override
@SafeVarargs
public final Builder system(Consumer... system) {
system(Stream.of(system).map(c -> SystemContentBlock.builder().applyMutation(c).build()).collect(Collectors.toList()));
return this;
}
public final InferenceConfiguration.Builder getInferenceConfig() {
return inferenceConfig != null ? inferenceConfig.toBuilder() : null;
}
public final void setInferenceConfig(InferenceConfiguration.BuilderImpl inferenceConfig) {
this.inferenceConfig = inferenceConfig != null ? inferenceConfig.build() : null;
}
@Override
public final Builder inferenceConfig(InferenceConfiguration inferenceConfig) {
this.inferenceConfig = inferenceConfig;
return this;
}
public final ToolConfiguration.Builder getToolConfig() {
return toolConfig != null ? toolConfig.toBuilder() : null;
}
public final void setToolConfig(ToolConfiguration.BuilderImpl toolConfig) {
this.toolConfig = toolConfig != null ? toolConfig.build() : null;
}
@Override
public final Builder toolConfig(ToolConfiguration toolConfig) {
this.toolConfig = toolConfig;
return this;
}
public final GuardrailConfiguration.Builder getGuardrailConfig() {
return guardrailConfig != null ? guardrailConfig.toBuilder() : null;
}
public final void setGuardrailConfig(GuardrailConfiguration.BuilderImpl guardrailConfig) {
this.guardrailConfig = guardrailConfig != null ? guardrailConfig.build() : null;
}
@Override
public final Builder guardrailConfig(GuardrailConfiguration guardrailConfig) {
this.guardrailConfig = guardrailConfig;
return this;
}
public final Document getAdditionalModelRequestFields() {
return additionalModelRequestFields;
}
public final void setAdditionalModelRequestFields(Document additionalModelRequestFields) {
this.additionalModelRequestFields = additionalModelRequestFields;
}
@Override
public final Builder additionalModelRequestFields(Document additionalModelRequestFields) {
this.additionalModelRequestFields = additionalModelRequestFields;
return this;
}
public final Collection getAdditionalModelResponseFieldPaths() {
if (additionalModelResponseFieldPaths instanceof SdkAutoConstructList) {
return null;
}
return additionalModelResponseFieldPaths;
}
public final void setAdditionalModelResponseFieldPaths(Collection additionalModelResponseFieldPaths) {
this.additionalModelResponseFieldPaths = ConverseRequestAdditionalModelResponseFieldPathsListCopier
.copy(additionalModelResponseFieldPaths);
}
@Override
public final Builder additionalModelResponseFieldPaths(Collection additionalModelResponseFieldPaths) {
this.additionalModelResponseFieldPaths = ConverseRequestAdditionalModelResponseFieldPathsListCopier
.copy(additionalModelResponseFieldPaths);
return this;
}
@Override
@SafeVarargs
public final Builder additionalModelResponseFieldPaths(String... additionalModelResponseFieldPaths) {
additionalModelResponseFieldPaths(Arrays.asList(additionalModelResponseFieldPaths));
return this;
}
@Override
public Builder overrideConfiguration(AwsRequestOverrideConfiguration overrideConfiguration) {
super.overrideConfiguration(overrideConfiguration);
return this;
}
@Override
public Builder overrideConfiguration(Consumer builderConsumer) {
super.overrideConfiguration(builderConsumer);
return this;
}
@Override
public ConverseRequest build() {
return new ConverseRequest(this);
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
}
}