software.amazon.awssdk.services.bedrock.DefaultBedrockAsyncClient Maven / Gradle / Ivy
Show all versions of bedrock 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.bedrock;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsAsyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.awscore.internal.AwsProtocolMetadata;
import software.amazon.awssdk.awscore.internal.AwsServiceProtocol;
import software.amazon.awssdk.awscore.retry.AwsRetryStrategy;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkPlugin;
import software.amazon.awssdk.core.SdkRequest;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.AsyncClientHandler;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.NoOpMetricCollector;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.retries.api.RetryStrategy;
import software.amazon.awssdk.services.bedrock.internal.BedrockServiceClientConfigurationBuilder;
import software.amazon.awssdk.services.bedrock.model.AccessDeniedException;
import software.amazon.awssdk.services.bedrock.model.BatchDeleteEvaluationJobRequest;
import software.amazon.awssdk.services.bedrock.model.BatchDeleteEvaluationJobResponse;
import software.amazon.awssdk.services.bedrock.model.BedrockException;
import software.amazon.awssdk.services.bedrock.model.ConflictException;
import software.amazon.awssdk.services.bedrock.model.CreateEvaluationJobRequest;
import software.amazon.awssdk.services.bedrock.model.CreateEvaluationJobResponse;
import software.amazon.awssdk.services.bedrock.model.CreateGuardrailRequest;
import software.amazon.awssdk.services.bedrock.model.CreateGuardrailResponse;
import software.amazon.awssdk.services.bedrock.model.CreateGuardrailVersionRequest;
import software.amazon.awssdk.services.bedrock.model.CreateGuardrailVersionResponse;
import software.amazon.awssdk.services.bedrock.model.CreateModelCopyJobRequest;
import software.amazon.awssdk.services.bedrock.model.CreateModelCopyJobResponse;
import software.amazon.awssdk.services.bedrock.model.CreateModelCustomizationJobRequest;
import software.amazon.awssdk.services.bedrock.model.CreateModelCustomizationJobResponse;
import software.amazon.awssdk.services.bedrock.model.CreateModelImportJobRequest;
import software.amazon.awssdk.services.bedrock.model.CreateModelImportJobResponse;
import software.amazon.awssdk.services.bedrock.model.CreateModelInvocationJobRequest;
import software.amazon.awssdk.services.bedrock.model.CreateModelInvocationJobResponse;
import software.amazon.awssdk.services.bedrock.model.CreateProvisionedModelThroughputRequest;
import software.amazon.awssdk.services.bedrock.model.CreateProvisionedModelThroughputResponse;
import software.amazon.awssdk.services.bedrock.model.DeleteCustomModelRequest;
import software.amazon.awssdk.services.bedrock.model.DeleteCustomModelResponse;
import software.amazon.awssdk.services.bedrock.model.DeleteGuardrailRequest;
import software.amazon.awssdk.services.bedrock.model.DeleteGuardrailResponse;
import software.amazon.awssdk.services.bedrock.model.DeleteImportedModelRequest;
import software.amazon.awssdk.services.bedrock.model.DeleteImportedModelResponse;
import software.amazon.awssdk.services.bedrock.model.DeleteModelInvocationLoggingConfigurationRequest;
import software.amazon.awssdk.services.bedrock.model.DeleteModelInvocationLoggingConfigurationResponse;
import software.amazon.awssdk.services.bedrock.model.DeleteProvisionedModelThroughputRequest;
import software.amazon.awssdk.services.bedrock.model.DeleteProvisionedModelThroughputResponse;
import software.amazon.awssdk.services.bedrock.model.GetCustomModelRequest;
import software.amazon.awssdk.services.bedrock.model.GetCustomModelResponse;
import software.amazon.awssdk.services.bedrock.model.GetEvaluationJobRequest;
import software.amazon.awssdk.services.bedrock.model.GetEvaluationJobResponse;
import software.amazon.awssdk.services.bedrock.model.GetFoundationModelRequest;
import software.amazon.awssdk.services.bedrock.model.GetFoundationModelResponse;
import software.amazon.awssdk.services.bedrock.model.GetGuardrailRequest;
import software.amazon.awssdk.services.bedrock.model.GetGuardrailResponse;
import software.amazon.awssdk.services.bedrock.model.GetImportedModelRequest;
import software.amazon.awssdk.services.bedrock.model.GetImportedModelResponse;
import software.amazon.awssdk.services.bedrock.model.GetInferenceProfileRequest;
import software.amazon.awssdk.services.bedrock.model.GetInferenceProfileResponse;
import software.amazon.awssdk.services.bedrock.model.GetModelCopyJobRequest;
import software.amazon.awssdk.services.bedrock.model.GetModelCopyJobResponse;
import software.amazon.awssdk.services.bedrock.model.GetModelCustomizationJobRequest;
import software.amazon.awssdk.services.bedrock.model.GetModelCustomizationJobResponse;
import software.amazon.awssdk.services.bedrock.model.GetModelImportJobRequest;
import software.amazon.awssdk.services.bedrock.model.GetModelImportJobResponse;
import software.amazon.awssdk.services.bedrock.model.GetModelInvocationJobRequest;
import software.amazon.awssdk.services.bedrock.model.GetModelInvocationJobResponse;
import software.amazon.awssdk.services.bedrock.model.GetModelInvocationLoggingConfigurationRequest;
import software.amazon.awssdk.services.bedrock.model.GetModelInvocationLoggingConfigurationResponse;
import software.amazon.awssdk.services.bedrock.model.GetProvisionedModelThroughputRequest;
import software.amazon.awssdk.services.bedrock.model.GetProvisionedModelThroughputResponse;
import software.amazon.awssdk.services.bedrock.model.InternalServerException;
import software.amazon.awssdk.services.bedrock.model.ListCustomModelsRequest;
import software.amazon.awssdk.services.bedrock.model.ListCustomModelsResponse;
import software.amazon.awssdk.services.bedrock.model.ListEvaluationJobsRequest;
import software.amazon.awssdk.services.bedrock.model.ListEvaluationJobsResponse;
import software.amazon.awssdk.services.bedrock.model.ListFoundationModelsRequest;
import software.amazon.awssdk.services.bedrock.model.ListFoundationModelsResponse;
import software.amazon.awssdk.services.bedrock.model.ListGuardrailsRequest;
import software.amazon.awssdk.services.bedrock.model.ListGuardrailsResponse;
import software.amazon.awssdk.services.bedrock.model.ListImportedModelsRequest;
import software.amazon.awssdk.services.bedrock.model.ListImportedModelsResponse;
import software.amazon.awssdk.services.bedrock.model.ListInferenceProfilesRequest;
import software.amazon.awssdk.services.bedrock.model.ListInferenceProfilesResponse;
import software.amazon.awssdk.services.bedrock.model.ListModelCopyJobsRequest;
import software.amazon.awssdk.services.bedrock.model.ListModelCopyJobsResponse;
import software.amazon.awssdk.services.bedrock.model.ListModelCustomizationJobsRequest;
import software.amazon.awssdk.services.bedrock.model.ListModelCustomizationJobsResponse;
import software.amazon.awssdk.services.bedrock.model.ListModelImportJobsRequest;
import software.amazon.awssdk.services.bedrock.model.ListModelImportJobsResponse;
import software.amazon.awssdk.services.bedrock.model.ListModelInvocationJobsRequest;
import software.amazon.awssdk.services.bedrock.model.ListModelInvocationJobsResponse;
import software.amazon.awssdk.services.bedrock.model.ListProvisionedModelThroughputsRequest;
import software.amazon.awssdk.services.bedrock.model.ListProvisionedModelThroughputsResponse;
import software.amazon.awssdk.services.bedrock.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.bedrock.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.bedrock.model.PutModelInvocationLoggingConfigurationRequest;
import software.amazon.awssdk.services.bedrock.model.PutModelInvocationLoggingConfigurationResponse;
import software.amazon.awssdk.services.bedrock.model.ResourceNotFoundException;
import software.amazon.awssdk.services.bedrock.model.ServiceQuotaExceededException;
import software.amazon.awssdk.services.bedrock.model.StopEvaluationJobRequest;
import software.amazon.awssdk.services.bedrock.model.StopEvaluationJobResponse;
import software.amazon.awssdk.services.bedrock.model.StopModelCustomizationJobRequest;
import software.amazon.awssdk.services.bedrock.model.StopModelCustomizationJobResponse;
import software.amazon.awssdk.services.bedrock.model.StopModelInvocationJobRequest;
import software.amazon.awssdk.services.bedrock.model.StopModelInvocationJobResponse;
import software.amazon.awssdk.services.bedrock.model.TagResourceRequest;
import software.amazon.awssdk.services.bedrock.model.TagResourceResponse;
import software.amazon.awssdk.services.bedrock.model.ThrottlingException;
import software.amazon.awssdk.services.bedrock.model.TooManyTagsException;
import software.amazon.awssdk.services.bedrock.model.UntagResourceRequest;
import software.amazon.awssdk.services.bedrock.model.UntagResourceResponse;
import software.amazon.awssdk.services.bedrock.model.UpdateGuardrailRequest;
import software.amazon.awssdk.services.bedrock.model.UpdateGuardrailResponse;
import software.amazon.awssdk.services.bedrock.model.UpdateProvisionedModelThroughputRequest;
import software.amazon.awssdk.services.bedrock.model.UpdateProvisionedModelThroughputResponse;
import software.amazon.awssdk.services.bedrock.model.ValidationException;
import software.amazon.awssdk.services.bedrock.transform.BatchDeleteEvaluationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateEvaluationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateGuardrailRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateGuardrailVersionRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateModelCopyJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateModelCustomizationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateModelImportJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateModelInvocationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.CreateProvisionedModelThroughputRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.DeleteCustomModelRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.DeleteGuardrailRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.DeleteImportedModelRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.DeleteModelInvocationLoggingConfigurationRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.DeleteProvisionedModelThroughputRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetCustomModelRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetEvaluationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetFoundationModelRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetGuardrailRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetImportedModelRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetInferenceProfileRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetModelCopyJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetModelCustomizationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetModelImportJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetModelInvocationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetModelInvocationLoggingConfigurationRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.GetProvisionedModelThroughputRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListCustomModelsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListEvaluationJobsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListFoundationModelsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListGuardrailsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListImportedModelsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListInferenceProfilesRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListModelCopyJobsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListModelCustomizationJobsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListModelImportJobsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListModelInvocationJobsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListProvisionedModelThroughputsRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.PutModelInvocationLoggingConfigurationRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.StopEvaluationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.StopModelCustomizationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.StopModelInvocationJobRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.UpdateGuardrailRequestMarshaller;
import software.amazon.awssdk.services.bedrock.transform.UpdateProvisionedModelThroughputRequestMarshaller;
import software.amazon.awssdk.utils.CompletableFutureUtils;
/**
* Internal implementation of {@link BedrockAsyncClient}.
*
* @see BedrockAsyncClient#builder()
*/
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultBedrockAsyncClient implements BedrockAsyncClient {
private static final Logger log = LoggerFactory.getLogger(DefaultBedrockAsyncClient.class);
private static final AwsProtocolMetadata protocolMetadata = AwsProtocolMetadata.builder()
.serviceProtocol(AwsServiceProtocol.REST_JSON).build();
private final AsyncClientHandler clientHandler;
private final AwsJsonProtocolFactory protocolFactory;
private final SdkClientConfiguration clientConfiguration;
protected DefaultBedrockAsyncClient(SdkClientConfiguration clientConfiguration) {
this.clientHandler = new AwsAsyncClientHandler(clientConfiguration);
this.clientConfiguration = clientConfiguration.toBuilder().option(SdkClientOption.SDK_CLIENT, this).build();
this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
}
/**
*
* Creates a batch deletion job. A model evaluation job can only be deleted if it has following status
* FAILED
, COMPLETED
, and STOPPED
. You can request up to 25 model evaluation
* jobs be deleted in a single request.
*
*
* @param batchDeleteEvaluationJobRequest
* @return A Java Future containing the result of the BatchDeleteEvaluationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.BatchDeleteEvaluationJob
* @see AWS API Documentation
*/
@Override
public CompletableFuture batchDeleteEvaluationJob(
BatchDeleteEvaluationJobRequest batchDeleteEvaluationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(batchDeleteEvaluationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, batchDeleteEvaluationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "BatchDeleteEvaluationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, BatchDeleteEvaluationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("BatchDeleteEvaluationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new BatchDeleteEvaluationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(batchDeleteEvaluationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* API operation for creating and managing Amazon Bedrock automatic model evaluation jobs and model evaluation jobs
* that use human workers. To learn more about the requirements for creating a model evaluation job see, Model evaluation.
*
*
* @param createEvaluationJobRequest
* @return A Java Future containing the result of the CreateEvaluationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateEvaluationJob
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture createEvaluationJob(
CreateEvaluationJobRequest createEvaluationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createEvaluationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createEvaluationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateEvaluationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateEvaluationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateEvaluationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateEvaluationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createEvaluationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates a guardrail to block topics and to implement safeguards for your generative AI applications.
*
*
* You can configure the following policies in a guardrail to avoid undesirable and harmful content, filter out
* denied topics and words, and remove sensitive information for privacy protection.
*
*
* -
*
* Content filters - Adjust filter strengths to block input prompts or model responses containing harmful
* content.
*
*
* -
*
* Denied topics - Define a set of topics that are undesirable in the context of your application. These
* topics will be blocked if detected in user queries or model responses.
*
*
* -
*
* Word filters - Configure filters to block undesirable words, phrases, and profanity. Such words can
* include offensive terms, competitor names etc.
*
*
* -
*
* Sensitive information filters - Block or mask sensitive information such as personally identifiable
* information (PII) or custom regex in user inputs and model responses.
*
*
*
*
* In addition to the above policies, you can also configure the messages to be returned to the user if a user input
* or model response is in violation of the policies defined in the guardrail.
*
*
* For more information, see Guardrails for Amazon Bedrock in
* the Amazon Bedrock User Guide.
*
*
* @param createGuardrailRequest
* @return A Java Future containing the result of the CreateGuardrail operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - TooManyTagsException The request contains more tags than can be associated with a resource (50 tags
* per resource). The maximum number of tags includes both existing tags and those included in your current
* request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateGuardrail
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture createGuardrail(CreateGuardrailRequest createGuardrailRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createGuardrailRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createGuardrailRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateGuardrail");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateGuardrailResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateGuardrail").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateGuardrailRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createGuardrailRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates a version of the guardrail. Use this API to create a snapshot of the guardrail when you are satisfied
* with a configuration, or to compare the configuration with another version.
*
*
* @param createGuardrailVersionRequest
* @return A Java Future containing the result of the CreateGuardrailVersion operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateGuardrailVersion
* @see AWS API Documentation
*/
@Override
public CompletableFuture createGuardrailVersion(
CreateGuardrailVersionRequest createGuardrailVersionRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createGuardrailVersionRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createGuardrailVersionRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateGuardrailVersion");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateGuardrailVersionResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateGuardrailVersion").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateGuardrailVersionRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createGuardrailVersionRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Copies a model to another region so that it can be used there. For more information, see Copy models to be used in other
* regions in the Amazon
* Bedrock User Guide.
*
*
* @param createModelCopyJobRequest
* @return A Java Future containing the result of the CreateModelCopyJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - InternalServerException An internal server error occurred. Retry your request.
* - TooManyTagsException The request contains more tags than can be associated with a resource (50 tags
* per resource). The maximum number of tags includes both existing tags and those included in your current
* request.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateModelCopyJob
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture createModelCopyJob(CreateModelCopyJobRequest createModelCopyJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createModelCopyJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createModelCopyJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateModelCopyJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateModelCopyJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateModelCopyJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateModelCopyJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createModelCopyJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates a fine-tuning job to customize a base model.
*
*
* You specify the base foundation model and the location of the training data. After the model-customization job
* completes successfully, your custom model resource will be ready to use. Amazon Bedrock returns validation loss
* metrics and output generations after the job completes.
*
*
* For information on the format of training and validation data, see Prepare the
* datasets.
*
*
* Model-customization jobs are asynchronous and the completion time depends on the base model and the
* training/validation data size. To monitor a job, use the GetModelCustomizationJob
operation to
* retrieve the job status.
*
*
* For more information, see Custom models in the Amazon Bedrock User Guide.
*
*
* @param createModelCustomizationJobRequest
* @return A Java Future containing the result of the CreateModelCustomizationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - TooManyTagsException The request contains more tags than can be associated with a resource (50 tags
* per resource). The maximum number of tags includes both existing tags and those included in your current
* request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateModelCustomizationJob
* @see AWS API Documentation
*/
@Override
public CompletableFuture createModelCustomizationJob(
CreateModelCustomizationJobRequest createModelCustomizationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createModelCustomizationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createModelCustomizationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateModelCustomizationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateModelCustomizationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateModelCustomizationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateModelCustomizationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createModelCustomizationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates a model import job to import model that you have customized in other environments, such as Amazon
* SageMaker. For more information, see Import a
* customized model
*
*
* @param createModelImportJobRequest
* @return A Java Future containing the result of the CreateModelImportJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - TooManyTagsException The request contains more tags than can be associated with a resource (50 tags
* per resource). The maximum number of tags includes both existing tags and those included in your current
* request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateModelImportJob
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture createModelImportJob(
CreateModelImportJobRequest createModelImportJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createModelImportJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createModelImportJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateModelImportJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateModelImportJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateModelImportJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateModelImportJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createModelImportJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates a batch inference job to invoke a model on multiple prompts. Format your data according to Format your inference data
* and upload it to an Amazon S3 bucket. For more information, see Process multiple prompts with
* batch inference.
*
*
* The response returns a jobArn
that you can use to stop or get details about the job.
*
*
* @param createModelInvocationJobRequest
* @return A Java Future containing the result of the CreateModelInvocationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateModelInvocationJob
* @see AWS API Documentation
*/
@Override
public CompletableFuture createModelInvocationJob(
CreateModelInvocationJobRequest createModelInvocationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createModelInvocationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, createModelInvocationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateModelInvocationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, CreateModelInvocationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateModelInvocationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateModelInvocationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createModelInvocationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Creates dedicated throughput for a base or custom model with the model units and for the duration that you
* specify. For pricing details, see Amazon Bedrock Pricing.
* For more information, see Provisioned Throughput in
* the Amazon Bedrock User
* Guide.
*
*
* @param createProvisionedModelThroughputRequest
* @return A Java Future containing the result of the CreateProvisionedModelThroughput operation returned by the
* service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - TooManyTagsException The request contains more tags than can be associated with a resource (50 tags
* per resource). The maximum number of tags includes both existing tags and those included in your current
* request.
* - ServiceQuotaExceededException The number of requests exceeds the service quota. Resubmit your request
* later.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.CreateProvisionedModelThroughput
* @see AWS API Documentation
*/
@Override
public CompletableFuture createProvisionedModelThroughput(
CreateProvisionedModelThroughputRequest createProvisionedModelThroughputRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(createProvisionedModelThroughputRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration,
createProvisionedModelThroughputRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "CreateProvisionedModelThroughput");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory
.createResponseHandler(operationMetadata, CreateProvisionedModelThroughputResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("CreateProvisionedModelThroughput").withProtocolMetadata(protocolMetadata)
.withMarshaller(new CreateProvisionedModelThroughputRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(createProvisionedModelThroughputRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes a custom model that you created earlier. For more information, see Custom models in the Amazon Bedrock User Guide.
*
*
* @param deleteCustomModelRequest
* @return A Java Future containing the result of the DeleteCustomModel operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.DeleteCustomModel
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture deleteCustomModel(DeleteCustomModelRequest deleteCustomModelRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteCustomModelRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteCustomModelRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteCustomModel");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteCustomModelResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteCustomModel").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteCustomModelRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(deleteCustomModelRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes a guardrail.
*
*
* -
*
* To delete a guardrail, only specify the ARN of the guardrail in the guardrailIdentifier
field. If
* you delete a guardrail, all of its versions will be deleted.
*
*
* -
*
* To delete a version of a guardrail, specify the ARN of the guardrail in the guardrailIdentifier
* field and the version in the guardrailVersion
field.
*
*
*
*
* @param deleteGuardrailRequest
* @return A Java Future containing the result of the DeleteGuardrail operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.DeleteGuardrail
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture deleteGuardrail(DeleteGuardrailRequest deleteGuardrailRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteGuardrailRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteGuardrailRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteGuardrail");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteGuardrailResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteGuardrail").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteGuardrailRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(deleteGuardrailRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes a custom model that you imported earlier. For more information, see Import a
* customized model in the Amazon Bedrock User Guide.
*
*
* @param deleteImportedModelRequest
* @return A Java Future containing the result of the DeleteImportedModel operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.DeleteImportedModel
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture deleteImportedModel(
DeleteImportedModelRequest deleteImportedModelRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteImportedModelRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, deleteImportedModelRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteImportedModel");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, DeleteImportedModelResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteImportedModel").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteImportedModelRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(deleteImportedModelRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Delete the invocation logging.
*
*
* @param deleteModelInvocationLoggingConfigurationRequest
* @return A Java Future containing the result of the DeleteModelInvocationLoggingConfiguration operation returned
* by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.DeleteModelInvocationLoggingConfiguration
* @see AWS API Documentation
*/
@Override
public CompletableFuture deleteModelInvocationLoggingConfiguration(
DeleteModelInvocationLoggingConfigurationRequest deleteModelInvocationLoggingConfigurationRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(
deleteModelInvocationLoggingConfigurationRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration,
deleteModelInvocationLoggingConfigurationRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteModelInvocationLoggingConfiguration");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory
.createResponseHandler(operationMetadata, DeleteModelInvocationLoggingConfigurationResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteModelInvocationLoggingConfiguration")
.withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteModelInvocationLoggingConfigurationRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(deleteModelInvocationLoggingConfigurationRequest));
CompletableFuture whenCompleted = executeFuture
.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Deletes a Provisioned Throughput. You can't delete a Provisioned Throughput before the commitment term is over.
* For more information, see Provisioned Throughput in
* the Amazon Bedrock User
* Guide.
*
*
* @param deleteProvisionedModelThroughputRequest
* @return A Java Future containing the result of the DeleteProvisionedModelThroughput operation returned by the
* service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - ConflictException Error occurred because of a conflict while performing an operation.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.DeleteProvisionedModelThroughput
* @see AWS API Documentation
*/
@Override
public CompletableFuture deleteProvisionedModelThroughput(
DeleteProvisionedModelThroughputRequest deleteProvisionedModelThroughputRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(deleteProvisionedModelThroughputRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration,
deleteProvisionedModelThroughputRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DeleteProvisionedModelThroughput");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory
.createResponseHandler(operationMetadata, DeleteProvisionedModelThroughputResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("DeleteProvisionedModelThroughput").withProtocolMetadata(protocolMetadata)
.withMarshaller(new DeleteProvisionedModelThroughputRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(deleteProvisionedModelThroughputRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Get the properties associated with a Amazon Bedrock custom model that you have created.For more information, see
* Custom models in the Amazon Bedrock User Guide.
*
*
* @param getCustomModelRequest
* @return A Java Future containing the result of the GetCustomModel operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetCustomModel
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture getCustomModel(GetCustomModelRequest getCustomModelRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getCustomModelRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getCustomModelRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetCustomModel");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetCustomModelResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetCustomModel").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetCustomModelRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getCustomModelRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Retrieves the properties associated with a model evaluation job, including the status of the job. For more
* information, see Model
* evaluation.
*
*
* @param getEvaluationJobRequest
* @return A Java Future containing the result of the GetEvaluationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetEvaluationJob
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture getEvaluationJob(GetEvaluationJobRequest getEvaluationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getEvaluationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getEvaluationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetEvaluationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetEvaluationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetEvaluationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetEvaluationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getEvaluationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Get details about a Amazon Bedrock foundation model.
*
*
* @param getFoundationModelRequest
* @return A Java Future containing the result of the GetFoundationModel operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetFoundationModel
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture getFoundationModel(GetFoundationModelRequest getFoundationModelRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getFoundationModelRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getFoundationModelRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetFoundationModel");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetFoundationModelResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetFoundationModel").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetFoundationModelRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getFoundationModelRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Gets details about a guardrail. If you don't specify a version, the response returns details for the
* DRAFT
version.
*
*
* @param getGuardrailRequest
* @return A Java Future containing the result of the GetGuardrail operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetGuardrail
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture getGuardrail(GetGuardrailRequest getGuardrailRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getGuardrailRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getGuardrailRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetGuardrail");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata,
GetGuardrailResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetGuardrail").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetGuardrailRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getGuardrailRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Gets properties associated with a customized model you imported.
*
*
* @param getImportedModelRequest
* @return A Java Future containing the result of the GetImportedModel operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetImportedModel
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture getImportedModel(GetImportedModelRequest getImportedModelRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getImportedModelRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getImportedModelRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetImportedModel");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetImportedModelResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetImportedModel").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetImportedModelRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getImportedModelRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Gets information about an inference profile. For more information, see the Amazon Bedrock User Guide.
*
*
* @param getInferenceProfileRequest
* @return A Java Future containing the result of the GetInferenceProfile operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetInferenceProfile
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture getInferenceProfile(
GetInferenceProfileRequest getInferenceProfileRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getInferenceProfileRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getInferenceProfileRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetInferenceProfile");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetInferenceProfileResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetInferenceProfile").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetInferenceProfileRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getInferenceProfileRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Retrieves information about a model copy job. For more information, see Copy models to be used in other
* regions in the Amazon
* Bedrock User Guide.
*
*
* @param getModelCopyJobRequest
* @return A Java Future containing the result of the GetModelCopyJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetModelCopyJob
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture getModelCopyJob(GetModelCopyJobRequest getModelCopyJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getModelCopyJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getModelCopyJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetModelCopyJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetModelCopyJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetModelCopyJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetModelCopyJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getModelCopyJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Retrieves the properties associated with a model-customization job, including the status of the job. For more
* information, see Custom
* models in the Amazon
* Bedrock User Guide.
*
*
* @param getModelCustomizationJobRequest
* @return A Java Future containing the result of the GetModelCustomizationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetModelCustomizationJob
* @see AWS API Documentation
*/
@Override
public CompletableFuture getModelCustomizationJob(
GetModelCustomizationJobRequest getModelCustomizationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getModelCustomizationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getModelCustomizationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetModelCustomizationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetModelCustomizationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetModelCustomizationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetModelCustomizationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getModelCustomizationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Retrieves the properties associated with import model job, including the status of the job. For more information,
* see Import a
* customized model in the Amazon Bedrock User Guide.
*
*
* @param getModelImportJobRequest
* @return A Java Future containing the result of the GetModelImportJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetModelImportJob
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture getModelImportJob(GetModelImportJobRequest getModelImportJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getModelImportJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getModelImportJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetModelImportJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetModelImportJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetModelImportJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetModelImportJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getModelImportJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Gets details about a batch inference job. For more information, see View
* details about a batch inference job
*
*
* @param getModelInvocationJobRequest
* @return A Java Future containing the result of the GetModelInvocationJob operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetModelInvocationJob
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture getModelInvocationJob(
GetModelInvocationJobRequest getModelInvocationJobRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getModelInvocationJobRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, getModelInvocationJobRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetModelInvocationJob");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetModelInvocationJobResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetModelInvocationJob").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetModelInvocationJobRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getModelInvocationJobRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Get the current configuration values for model invocation logging.
*
*
* @param getModelInvocationLoggingConfigurationRequest
* @return A Java Future containing the result of the GetModelInvocationLoggingConfiguration operation returned by
* the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetModelInvocationLoggingConfiguration
* @see AWS API Documentation
*/
@Override
public CompletableFuture getModelInvocationLoggingConfiguration(
GetModelInvocationLoggingConfigurationRequest getModelInvocationLoggingConfigurationRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getModelInvocationLoggingConfigurationRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration,
getModelInvocationLoggingConfigurationRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetModelInvocationLoggingConfiguration");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory
.createResponseHandler(operationMetadata, GetModelInvocationLoggingConfigurationResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetModelInvocationLoggingConfiguration").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetModelInvocationLoggingConfigurationRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getModelInvocationLoggingConfigurationRequest));
CompletableFuture whenCompleted = executeFuture
.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns details for a Provisioned Throughput. For more information, see Provisioned Throughput in
* the Amazon Bedrock User
* Guide.
*
*
* @param getProvisionedModelThroughputRequest
* @return A Java Future containing the result of the GetProvisionedModelThroughput operation returned by the
* service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.GetProvisionedModelThroughput
* @see AWS API Documentation
*/
@Override
public CompletableFuture getProvisionedModelThroughput(
GetProvisionedModelThroughputRequest getProvisionedModelThroughputRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(getProvisionedModelThroughputRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration,
getProvisionedModelThroughputRequest.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetProvisionedModelThroughput");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, GetProvisionedModelThroughputResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("GetProvisionedModelThroughput").withProtocolMetadata(protocolMetadata)
.withMarshaller(new GetProvisionedModelThroughputRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(getProvisionedModelThroughputRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of the custom models that you have created with the CreateModelCustomizationJob
* operation.
*
*
* For more information, see Custom models in the Amazon Bedrock User Guide.
*
*
* @param listCustomModelsRequest
* @return A Java Future containing the result of the ListCustomModels operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListCustomModels
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture listCustomModels(ListCustomModelsRequest listCustomModelsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listCustomModelsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listCustomModelsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListCustomModels");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListCustomModelsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListCustomModels").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListCustomModelsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listCustomModelsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Lists model evaluation jobs.
*
*
* @param listEvaluationJobsRequest
* @return A Java Future containing the result of the ListEvaluationJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListEvaluationJobs
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture listEvaluationJobs(ListEvaluationJobsRequest listEvaluationJobsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listEvaluationJobsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listEvaluationJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListEvaluationJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListEvaluationJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListEvaluationJobs").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListEvaluationJobsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listEvaluationJobsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Lists Amazon Bedrock foundation models that you can use. You can filter the results with the request parameters.
* For more information, see Foundation models in the
* Amazon Bedrock User
* Guide.
*
*
* @param listFoundationModelsRequest
* @return A Java Future containing the result of the ListFoundationModels operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListFoundationModels
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture listFoundationModels(
ListFoundationModelsRequest listFoundationModelsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listFoundationModelsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listFoundationModelsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListFoundationModels");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListFoundationModelsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListFoundationModels").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListFoundationModelsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listFoundationModelsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Lists details about all the guardrails in an account. To list the DRAFT
version of all your
* guardrails, don't specify the guardrailIdentifier
field. To list all versions of a guardrail,
* specify the ARN of the guardrail in the guardrailIdentifier
field.
*
*
* You can set the maximum number of results to return in a response in the maxResults
field. If there
* are more results than the number you set, the response returns a nextToken
that you can send in
* another ListGuardrails
request to see the next batch of results.
*
*
* @param listGuardrailsRequest
* @return A Java Future containing the result of the ListGuardrails operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListGuardrails
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture listGuardrails(ListGuardrailsRequest listGuardrailsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listGuardrailsRequest, this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listGuardrailsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListGuardrails");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListGuardrailsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListGuardrails").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListGuardrailsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listGuardrailsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of models you've imported. You can filter the results to return based on one or more criteria. For
* more information, see Import a
* customized model in the Amazon Bedrock User Guide.
*
*
* @param listImportedModelsRequest
* @return A Java Future containing the result of the ListImportedModels operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListImportedModels
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture listImportedModels(ListImportedModelsRequest listImportedModelsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listImportedModelsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listImportedModelsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListImportedModels");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListImportedModelsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListImportedModels").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListImportedModelsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listImportedModelsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of inference profiles that you can use.
*
*
* @param listInferenceProfilesRequest
* @return A Java Future containing the result of the ListInferenceProfiles operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListInferenceProfiles
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture listInferenceProfiles(
ListInferenceProfilesRequest listInferenceProfilesRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listInferenceProfilesRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listInferenceProfilesRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListInferenceProfiles");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListInferenceProfilesResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListInferenceProfiles").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListInferenceProfilesRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listInferenceProfilesRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of model copy jobs that you have submitted. You can filter the jobs to return based on one or more
* criteria. For more information, see Copy models to be used in other
* regions in the Amazon
* Bedrock User Guide.
*
*
* @param listModelCopyJobsRequest
* @return A Java Future containing the result of the ListModelCopyJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - ResourceNotFoundException The specified resource Amazon Resource Name (ARN) was not found. Check the
* Amazon Resource Name (ARN) and try your request again.
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListModelCopyJobs
* @see AWS API
* Documentation
*/
@Override
public CompletableFuture listModelCopyJobs(ListModelCopyJobsRequest listModelCopyJobsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listModelCopyJobsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listModelCopyJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListModelCopyJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListModelCopyJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListModelCopyJobs").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListModelCopyJobsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listModelCopyJobsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of model customization jobs that you have submitted. You can filter the jobs to return based on
* one or more criteria.
*
*
* For more information, see Custom models in the Amazon Bedrock User Guide.
*
*
* @param listModelCustomizationJobsRequest
* @return A Java Future containing the result of the ListModelCustomizationJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListModelCustomizationJobs
* @see AWS API Documentation
*/
@Override
public CompletableFuture listModelCustomizationJobs(
ListModelCustomizationJobsRequest listModelCustomizationJobsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listModelCustomizationJobsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listModelCustomizationJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListModelCustomizationJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListModelCustomizationJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListModelCustomizationJobs").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListModelCustomizationJobsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listModelCustomizationJobsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Returns a list of import jobs you've submitted. You can filter the results to return based on one or more
* criteria. For more information, see Import a
* customized model in the Amazon Bedrock User Guide.
*
*
* @param listModelImportJobsRequest
* @return A Java Future containing the result of the ListModelImportJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListModelImportJobs
* @see AWS
* API Documentation
*/
@Override
public CompletableFuture listModelImportJobs(
ListModelImportJobsRequest listModelImportJobsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listModelImportJobsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listModelImportJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListModelImportJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListModelImportJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListModelImportJobs").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListModelImportJobsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listModelImportJobsRequest));
CompletableFuture whenCompleted = executeFuture.whenComplete((r, e) -> {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
});
executeFuture = CompletableFutureUtils.forwardExceptionTo(whenCompleted, executeFuture);
return executeFuture;
} catch (Throwable t) {
metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect()));
return CompletableFutureUtils.failedFuture(t);
}
}
/**
*
* Lists all batch inference jobs in the account. For more information, see View
* details about a batch inference job.
*
*
* @param listModelInvocationJobsRequest
* @return A Java Future containing the result of the ListModelInvocationJobs operation returned by the service.
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions. The exception returned is wrapped with CompletionException, so you need to invoke
* {@link Throwable#getCause} to retrieve the underlying exception.
*
* - AccessDeniedException The request is denied because of missing access permissions.
* - ValidationException Input validation failed. Check your request parameters and retry the request.
* - InternalServerException An internal server error occurred. Retry your request.
* - ThrottlingException The number of requests exceeds the limit. Resubmit your request later.
* - SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.
* - SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.
* - BedrockException Base class for all service exceptions. Unknown exceptions will be thrown as an
* instance of this type.
*
* @sample BedrockAsyncClient.ListModelInvocationJobs
* @see AWS API Documentation
*/
@Override
public CompletableFuture listModelInvocationJobs(
ListModelInvocationJobsRequest listModelInvocationJobsRequest) {
SdkClientConfiguration clientConfiguration = updateSdkClientConfiguration(listModelInvocationJobsRequest,
this.clientConfiguration);
List metricPublishers = resolveMetricPublishers(clientConfiguration, listModelInvocationJobsRequest
.overrideConfiguration().orElse(null));
MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector
.create("ApiCall");
try {
apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "Bedrock");
apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListModelInvocationJobs");
JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false)
.isPayloadJson(true).build();
HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(
operationMetadata, ListModelInvocationJobsResponse::builder);
HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory,
operationMetadata);
CompletableFuture executeFuture = clientHandler
.execute(new ClientExecutionParams()
.withOperationName("ListModelInvocationJobs").withProtocolMetadata(protocolMetadata)
.withMarshaller(new ListModelInvocationJobsRequestMarshaller(protocolFactory))
.withResponseHandler(responseHandler).withErrorResponseHandler(errorResponseHandler)
.withRequestConfiguration(clientConfiguration).withMetricCollector(apiCallMetricCollector)
.withInput(listModelInvocationJobsRequest));
CompletableFuture