Class AbstractBedrockApi<I,O,SO>

java.lang.Object
org.springframework.ai.bedrock.api.AbstractBedrockApi<I,O,SO>
Type Parameters:
I - The input request type.
O - The output response type.
SO - The streaming response type. For some models this type can be the same as the output response type.
Direct Known Subclasses:
Ai21Jurassic2ChatBedrockApi, AnthropicChatBedrockApi, CohereChatBedrockApi, CohereEmbeddingBedrockApi, Llama2ChatBedrockApi, TitanChatBedrockApi, TitanEmbeddingBedrockApi

public abstract class AbstractBedrockApi<I,O,SO> extends Object
Abstract class for the Bedrock API. It provides the basic functionality to invoke the chat completion model and receive the response for streaming and non-streaming requests.

https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids-arns.html

https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess

Since:
0.8.0
Author:
Christian Tzolov
See Also:
  • Constructor Details

    • AbstractBedrockApi

      public AbstractBedrockApi(String modelId, String region)
      Create a new AbstractBedrockApi instance using default credentials provider and object mapper.
      Parameters:
      modelId - The model id to use.
      region - The AWS region to use.
    • AbstractBedrockApi

      public AbstractBedrockApi(String modelId, software.amazon.awssdk.auth.credentials.AwsCredentialsProvider credentialsProvider, String region, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Create a new AbstractBedrockApi instance using the provided credentials provider, region and object mapper.
      Parameters:
      modelId - The model id to use.
      credentialsProvider - The credentials provider to connect to AWS.
      region - The AWS region to use.
      objectMapper - The object mapper to use for JSON serialization and deserialization.
  • Method Details

    • getModelId

      public String getModelId()
      Returns:
      The model id.
    • getRegion

      public String getRegion()
      Returns:
      The AWS region.
    • embedding

      protected O embedding(I request)
      Compute the embedding for the given text.
      Parameters:
      request - The embedding request.
      Returns:
      Returns the embedding response.
    • chatCompletion

      protected O chatCompletion(I request)
      Chat completion invocation.
      Parameters:
      request - The chat completion request.
      Returns:
      The chat completion response.
    • chatCompletionStream

      protected reactor.core.publisher.Flux<SO> chatCompletionStream(I request)
      Chat completion invocation with streaming response.
      Parameters:
      request - The chat completion request.
      Returns:
      The chat completion response stream.
    • internalInvocation

      protected O internalInvocation(I request, Class<O> clazz)
      Internal method to invoke the model and return the response. https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_InvokeModel.html https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/bedrockruntime/BedrockRuntimeClient.html#invokeModel
      Parameters:
      request - Model invocation request.
      clazz - The response class type
      Returns:
      The model invocation response.
    • internalInvocationStream

      protected reactor.core.publisher.Flux<SO> internalInvocationStream(I request, Class<SO> clazz)
      Internal method to invoke the model and return the response stream.
      Parameters:
      request - Model invocation request.
      clazz - Response class type.
      Returns:
      The model invocation response stream.