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
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Encapsulates the metrics about the model invocation. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractBedrockApi
(String modelId, String region) Create a new AbstractBedrockApi instance using default credentials provider and object mapper.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. -
Method Summary
Modifier and TypeMethodDescriptionprotected O
chatCompletion
(I request) Chat completion invocation.protected reactor.core.publisher.Flux
<SO> chatCompletionStream
(I request) Chat completion invocation with streaming response.protected O
Compute the embedding for the given text.protected O
internalInvocation
(I request, Class<O> clazz) Internal method to invoke the model and return the response.protected reactor.core.publisher.Flux
<SO> internalInvocationStream
(I request, Class<SO> clazz) Internal method to invoke the model and return the response stream.
-
Constructor Details
-
AbstractBedrockApi
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
- Returns:
- The model id.
-
getRegion
- Returns:
- The AWS region.
-
embedding
Compute the embedding for the given text.- Parameters:
request
- The embedding request.- Returns:
- Returns the embedding response.
-
chatCompletion
Chat completion invocation.- Parameters:
request
- The chat completion request.- Returns:
- The chat completion response.
-
chatCompletionStream
Chat completion invocation with streaming response.- Parameters:
request
- The chat completion request.- Returns:
- The chat completion response stream.
-
internalInvocation
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
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.
-