From f9f6247f7e2f2020a20145382bc6cbe2463b59db Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Sat, 22 Jun 2024 11:44:02 +0200 Subject: [PATCH] AWS/Bedrock housekeeping updates - upadate bedrockruntime version to 2.26.7 and align it with aws sdk dependecy. - minor ITs configuration, consistency and statbility fixes Use the EnvironmentVariableCredentialsProvider instead of the Profile credential provider. - update the Bedrock getting started documentation. - update the Genemi Prerequisites docs. --- .../bedrock/anthropic/BedrockAnthropicChatModelIT.java | 6 +++++- .../ai/bedrock/cohere/api/CohereChatBedrockApiIT.java | 5 ++++- .../jurassic2/BedrockAi21Jurassic2ChatModelIT.java | 3 ++- .../jurassic2/api/Ai21Jurassic2ChatBedrockApiIT.java | 8 ++++++-- .../ai/bedrock/titan/api/TitanChatBedrockApiIT.java | 5 ++++- pom.xml | 8 ++++++-- .../src/main/antora/modules/ROOT/pages/api/bedrock.adoc | 6 +++--- .../ROOT/pages/api/chat/vertexai-gemini-chat.adoc | 9 +++++---- 8 files changed, 35 insertions(+), 15 deletions(-) diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java index b2b09fc8e..530101a83 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/anthropic/BedrockAnthropicChatModelIT.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.stream.Collectors; import com.fasterxml.jackson.databind.ObjectMapper; + +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import org.slf4j.Logger; @@ -125,6 +127,7 @@ class BedrockAnthropicChatModelIT { assertThat(list).hasSize(5); } + @Disabled @Test void mapOutputConvert() { MapOutputConverter outputConverter = new MapOutputConverter(); @@ -147,6 +150,7 @@ class BedrockAnthropicChatModelIT { record ActorsFilmsRecord(String actor, List movies) { } + @Disabled @Test void beanOutputConverterRecords() { @@ -203,7 +207,7 @@ class BedrockAnthropicChatModelIT { @Bean public AnthropicChatBedrockApi anthropicApi() { - return new AnthropicChatBedrockApi(AnthropicChatBedrockApi.AnthropicChatModel.CLAUDE_V2.id(), + return new AnthropicChatBedrockApi(AnthropicChatBedrockApi.AnthropicChatModel.CLAUDE_V21.id(), EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), new ObjectMapper(), Duration.ofMinutes(2)); } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/api/CohereChatBedrockApiIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/api/CohereChatBedrockApiIT.java index 540a6bd2b..68447ea94 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/api/CohereChatBedrockApiIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/cohere/api/CohereChatBedrockApiIT.java @@ -21,6 +21,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import reactor.core.publisher.Flux; +import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; import software.amazon.awssdk.regions.Region; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatModel; @@ -28,6 +29,7 @@ import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChat import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatRequest.Truncate; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatResponse; import org.springframework.ai.bedrock.cohere.api.CohereChatBedrockApi.CohereChatResponse.Generation.FinishReason; +import org.springframework.ai.model.ModelOptionsUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy;; @@ -40,7 +42,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;; public class CohereChatBedrockApiIT { private CohereChatBedrockApi cohereChatApi = new CohereChatBedrockApi(CohereChatModel.COHERE_COMMAND_V14.id(), - Region.US_EAST_1.id(), Duration.ofMinutes(2)); + EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), ModelOptionsUtils.OBJECT_MAPPER, + Duration.ofMinutes(2)); @Test public void requestBuilder() { diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatModelIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatModelIT.java index 5ab957e79..b468fbcab 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatModelIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/BedrockAi21Jurassic2ChatModelIT.java @@ -127,6 +127,7 @@ class BedrockAi21Jurassic2ChatModelIT { } + @Disabled("Jurrasic2 is very unstable") @Test void simpleChatResponse() { UserMessage userMessage = new UserMessage("Tell me a joke about AI."); @@ -146,7 +147,7 @@ class BedrockAi21Jurassic2ChatModelIT { @Bean public Ai21Jurassic2ChatBedrockApi jurassic2ChatBedrockApi() { return new Ai21Jurassic2ChatBedrockApi( - Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel.AI21_J2_MID_V1.id(), + Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel.AI21_J2_ULTRA_V1.id(), EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), new ObjectMapper(), Duration.ofMinutes(2)); } diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/api/Ai21Jurassic2ChatBedrockApiIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/api/Ai21Jurassic2ChatBedrockApiIT.java index 8525471d1..0360c0c7d 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/api/Ai21Jurassic2ChatBedrockApiIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/jurassic2/api/Ai21Jurassic2ChatBedrockApiIT.java @@ -20,11 +20,14 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; + +import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; import software.amazon.awssdk.regions.Region; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatModel; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatRequest; import org.springframework.ai.bedrock.jurassic2.api.Ai21Jurassic2ChatBedrockApi.Ai21Jurassic2ChatResponse; +import org.springframework.ai.model.ModelOptionsUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -35,8 +38,9 @@ import static org.assertj.core.api.Assertions.assertThat; @EnabledIfEnvironmentVariable(named = "AWS_SECRET_ACCESS_KEY", matches = ".*") public class Ai21Jurassic2ChatBedrockApiIT { - Ai21Jurassic2ChatBedrockApi api = new Ai21Jurassic2ChatBedrockApi(Ai21Jurassic2ChatModel.AI21_J2_ULTRA_V1.id(), - Region.US_EAST_1.id(), Duration.ofMinutes(2)); + Ai21Jurassic2ChatBedrockApi api = new Ai21Jurassic2ChatBedrockApi(Ai21Jurassic2ChatModel.AI21_J2_MID_V1.id(), + EnvironmentVariableCredentialsProvider.create(), Region.US_EAST_1.id(), ModelOptionsUtils.OBJECT_MAPPER, + Duration.ofMinutes(2)); @Test public void chatCompletion() { diff --git a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/api/TitanChatBedrockApiIT.java b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/api/TitanChatBedrockApiIT.java index e7bb1f8bf..4a05080b0 100644 --- a/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/api/TitanChatBedrockApiIT.java +++ b/models/spring-ai-bedrock/src/test/java/org/springframework/ai/bedrock/titan/api/TitanChatBedrockApiIT.java @@ -22,12 +22,14 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; import reactor.core.publisher.Flux; +import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; import software.amazon.awssdk.regions.Region; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatModel; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatRequest; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatResponse; import org.springframework.ai.bedrock.titan.api.TitanChatBedrockApi.TitanChatResponseChunk; +import org.springframework.ai.model.ModelOptionsUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -39,7 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat; public class TitanChatBedrockApiIT { TitanChatBedrockApi titanBedrockApi = new TitanChatBedrockApi(TitanChatModel.TITAN_TEXT_EXPRESS_V1.id(), - Region.EU_CENTRAL_1.id(), Duration.ofMinutes(2)); + EnvironmentVariableCredentialsProvider.create(), Region.EU_CENTRAL_1.id(), ModelOptionsUtils.OBJECT_MAPPER, + Duration.ofMinutes(2)); TitanChatRequest titanChatRequest = TitanChatRequest.builder("Give me the names of 3 famous pirates?") .withTemperature(0.5f) diff --git a/pom.xml b/pom.xml index a70d22acd..e4faa155b 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,11 @@ 1.0.0-beta.8 1.0.0 4.31.1 - 2.25.3 + + + 2.26.7 + 2.26.7 + 2.16.1 0.28.0 1.17.0 @@ -178,7 +182,7 @@ 1.9.1 0.5.0 2.10.1 - 2.20.161 + 5.3.1 diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc index f8b2b2062..bd0037874 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/bedrock.adoc @@ -10,9 +10,9 @@ Additionally, Spring AI provides Spring Auto-Configurations and Boot Starters fo There are a few steps to get started -* *Add Boot Starter*: Add the Spring Boot starter for Bedrock to your project. -* *Obtain AWS credentials*: If you don't have an AWS account and AWS CLI configured yet, this video guide can help you configure it: link:https://youtu.be/gswVHTrRX8I?si=buaY7aeI0l3-bBVb[AWS CLI & SDK Setup in Less Than 4 Minutes!]. You should be able to obtain your access and security keys. -* *Enable Bedrock models to use*: Go to link:https://us-east-1.console.aws.amazon.com/bedrock/home[Amazon Bedrock] and from the link:https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess[Model Access] menu on the left, configure access to the models you are going to use. +* Add the Spring Boot starter for Bedrock to your project. +* Obtain AWS credentials: If you don't have an AWS account and AWS CLI configured yet, this video guide can help you configure it: link:https://youtu.be/gswVHTrRX8I?si=buaY7aeI0l3-bBVb[AWS CLI & SDK Setup in Less Than 4 Minutes!]. You should be able to obtain your access and security keys. +* Enable the Models to use: Go to link:https://us-east-1.console.aws.amazon.com/bedrock/home[Amazon Bedrock] and from the link:https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess[Model Access] menu on the left, configure access to the models you are going to use. === Project Dependencies diff --git a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc index 2f362a6a9..ed9a351cc 100644 --- a/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc +++ b/spring-ai-docs/src/main/antora/modules/ROOT/pages/api/chat/vertexai-gemini-chat.adoc @@ -10,13 +10,14 @@ link:https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemin == Prerequisites -Set up your Java Development Environment. -Authenticate by running the following command. Replace `PROJECT_ID` with your Google Cloud project ID and `ACCOUNT` with your Google Cloud username. +- Install the link:https://cloud.google.com/sdk/docs/install[gcloud] CLI, apropriate for you OS. +- Authenticate by running the following command. +Replace `PROJECT_ID` with your Google Cloud project ID and `ACCOUNT` with your Google Cloud username. [source] ---- -gcloud config set project PROJECT_ID && -gcloud auth application-default login ACCOUNT +gcloud config set project && +gcloud auth application-default login ---- == Auto-configuration