diff --git a/docs/services/bedrock.md b/docs/services/bedrock.md index c7d5cc4264..8008011fb4 100644 --- a/docs/services/bedrock.md +++ b/docs/services/bedrock.md @@ -134,9 +134,10 @@ The answers depend on the calling Region, as on AWS: the calling Region, so `us.amazon.nova-lite-v1:0` called from `us-west-1` routes to four Regions and from `us-east-1` to three. `GetInferenceProfile` on a profile the Region cannot use returns `ResourceNotFoundException`. -- `inferenceTypesSupported` is `ON_DEMAND` only where the model is served in the Region - itself, and empty where it is reachable only through an inference profile, so - `byInferenceType=ON_DEMAND` leaves those out. +- `inferenceTypesSupported` includes `ON_DEMAND` where the model is served in the Region + itself, and `INFERENCE_PROFILE` where a seeded system-defined profile can be called from + the Region. A model reachable only through a profile reports `INFERENCE_PROFILE` without + `ON_DEMAND`, so `byInferenceType=ON_DEMAND` leaves those out. - `modelArn` is `arn::bedrock:::foundation-model/`, and the system-defined `inferenceProfileArn` carries the calling Region and account. `GetInferenceProfile` answers an ARN of another service or without an account with diff --git a/src/main/java/io/floci/aws/services/bedrock/BedrockController.java b/src/main/java/io/floci/aws/services/bedrock/BedrockController.java index 334fdd229c..ef851d7d7e 100644 --- a/src/main/java/io/floci/aws/services/bedrock/BedrockController.java +++ b/src/main/java/io/floci/aws/services/bedrock/BedrockController.java @@ -349,6 +349,10 @@ public class BedrockController { if (model.servedInRegion(region)) { inferenceTypes.add("ON_DEMAND"); } + if (BedrockModelCatalog.profilesFrom(region).stream() + .anyMatch(profile -> profile.modelId().equals(model.modelId()))) { + inferenceTypes.add("INFERENCE_PROFILE"); + } node.putObject("modelLifecycle").put("status", model.lifecycleStatus()); return node; } diff --git a/src/test/java/io/floci/aws/services/bedrock/BedrockInferenceProfileMetadataIntegrationTest.java b/src/test/java/io/floci/aws/services/bedrock/BedrockInferenceProfileMetadataIntegrationTest.java new file mode 100644 index 0000000000..ead8c50b5b --- /dev/null +++ b/src/test/java/io/floci/aws/services/bedrock/BedrockInferenceProfileMetadataIntegrationTest.java @@ -0,0 +1,78 @@ +package io.floci.aws.services.bedrock; + +import io.floci.aws.testing.AwsTestClients; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.bedrock.BedrockClient; +import software.amazon.awssdk.services.bedrock.model.FoundationModelDetails; +import software.amazon.awssdk.services.bedrock.model.FoundationModelSummary; +import software.amazon.awssdk.services.bedrock.model.ValidationException; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@QuarkusTest +class BedrockInferenceProfileMetadataIntegrationTest { + + private static final String MODEL = "amazon.nova-lite-v1:0"; + + @Test + void getFoundationModelAdvertisesOnDemandAndInferenceProfileSupport() { + try (BedrockClient client = AwsTestClients.create(BedrockClient.builder(), "741623800022", Region.US_EAST_1)) { + FoundationModelDetails model = client.getFoundationModel(request -> request.modelIdentifier(MODEL)) + .modelDetails(); + assertEquals(MODEL, model.modelId()); + assertEquals(List.of("ON_DEMAND", "INFERENCE_PROFILE"), model.inferenceTypesSupportedAsStrings()); + } + } + + @Test + void modelWithoutAProfileOnlyAdvertisesOnDemandSupport() { + try (BedrockClient client = AwsTestClients.create(BedrockClient.builder(), "741623800022", Region.US_EAST_1)) { + String modelId = "amazon.titan-embed-text-v2:0"; + assertEquals(List.of("ON_DEMAND"), client.getFoundationModel(request -> request + .modelIdentifier(modelId)).modelDetails().inferenceTypesSupportedAsStrings()); + FoundationModelSummary listed = client.listFoundationModels(request -> { }).modelSummaries().stream() + .filter(model -> modelId.equals(model.modelId())).findFirst().orElseThrow(); + assertEquals(List.of("ON_DEMAND"), listed.inferenceTypesSupportedAsStrings()); + } + } + + @Test + void listFoundationModelsAdvertisesOnDemandAndInferenceProfileSupport() { + try (BedrockClient client = AwsTestClients.create(BedrockClient.builder(), "741623800022", Region.US_EAST_1)) { + FoundationModelSummary model = client.listFoundationModels(request -> { }).modelSummaries().stream() + .filter(candidate -> MODEL.equals(candidate.modelId())).findFirst().orElseThrow(); + assertEquals(List.of("ON_DEMAND", "INFERENCE_PROFILE"), model.inferenceTypesSupportedAsStrings()); + } + } + + @Test + void profileOnlyRegionAdvertisesOnlyInferenceProfilesOnGetAndList() { + String modelId = "amazon.nova-micro-v1:0"; + try (BedrockClient client = AwsTestClients.create(BedrockClient.builder(), "741623800022", Region.EU_CENTRAL_1)) { + assertEquals(List.of("INFERENCE_PROFILE"), client.getFoundationModel(request -> request + .modelIdentifier(modelId)).modelDetails().inferenceTypesSupportedAsStrings()); + FoundationModelSummary listed = client.listFoundationModels(request -> { }).modelSummaries().stream() + .filter(model -> modelId.equals(model.modelId())).findFirst().orElseThrow(); + assertEquals(List.of("INFERENCE_PROFILE"), listed.inferenceTypesSupportedAsStrings()); + } + } + + @Test + void unavailableRegionExcludesTheModelAndRetainsGetValidation() { + try (BedrockClient client = AwsTestClients.create(BedrockClient.builder(), "741623800022", + Region.AP_NORTHEAST_3)) { + ValidationException error = assertThrows(ValidationException.class, + () -> client.getFoundationModel(request -> request.modelIdentifier(MODEL))); + assertEquals(400, error.statusCode()); + assertFalse(client.listFoundationModels(request -> { }).modelSummaries().stream() + .anyMatch(model -> MODEL.equals(model.modelId()))); + } + } + +} diff --git a/src/test/java/io/floci/aws/services/bedrock/BedrockModelCatalogIntegrationTest.java b/src/test/java/io/floci/aws/services/bedrock/BedrockModelCatalogIntegrationTest.java index b6f57f868a..5580607134 100644 --- a/src/test/java/io/floci/aws/services/bedrock/BedrockModelCatalogIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/bedrock/BedrockModelCatalogIntegrationTest.java @@ -146,7 +146,7 @@ class BedrockModelCatalogIntegrationTest { try (BedrockClient client = client("eu-central-1")) { FoundationModelSummary novaMicro = client.listFoundationModels(request -> { }).modelSummaries().stream() .filter(model -> model.modelId().equals(NOVA_MICRO)).findFirst().orElseThrow(); - assertTrue(novaMicro.inferenceTypesSupported().isEmpty(), + assertEquals(List.of("INFERENCE_PROFILE"), novaMicro.inferenceTypesSupportedAsStrings(), "Nova Micro is reachable from eu-central-1 only through eu." + NOVA_MICRO); List onDemand = client.listFoundationModels(request -> request