From 7c98c721ecce71eefbc4470e72068b2bc56be920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20D=C3=BCmont?= Date: Tue, 15 Oct 2024 16:28:59 +0200 Subject: [PATCH] Fix test --- .../com/sap/ai/sdk/core/AiCoreDeployment.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/sap/ai/sdk/core/AiCoreDeployment.java b/core/src/main/java/com/sap/ai/sdk/core/AiCoreDeployment.java index 92b8105e..721b9d74 100644 --- a/core/src/main/java/com/sap/ai/sdk/core/AiCoreDeployment.java +++ b/core/src/main/java/com/sap/ai/sdk/core/AiCoreDeployment.java @@ -18,7 +18,7 @@ import lombok.RequiredArgsConstructor; /** Connectivity convenience methods for AI Core with deployment. */ -@RequiredArgsConstructor(access = AccessLevel.PUBLIC) +@RequiredArgsConstructor(access = AccessLevel.PROTECTED) public class AiCoreDeployment implements AiCoreDestination { private static Map CACHE = new LinkedHashMap<>(); @@ -36,6 +36,18 @@ public class AiCoreDeployment implements AiCoreDestination { @Nonnull private final String resourceGroup; + /** + * Default constructor with "default" resource group. + * + * @param service The AI Core service. + * @param deploymentId The deployment id handler. + */ + public AiCoreDeployment( + @Nonnull final AiCoreService service, + @Nonnull final Function deploymentId) { + this(service, deploymentId, "default"); + } + /** * Create a new instance of the AI Core service with a deployment. * @@ -47,7 +59,7 @@ public class AiCoreDeployment implements AiCoreDestination { public static AiCoreDeployment forModelName( @Nonnull final AiCoreService service, @Nonnull final String modelName) { final Predicate p = deployment -> isDeploymentOfModel(modelName, deployment); - return new AiCoreDeployment(service, obj -> obj.getDeploymentId(p), "default"); + return new AiCoreDeployment(service, obj -> obj.getDeploymentId(service.client(), p)); } /** @@ -61,7 +73,7 @@ public static AiCoreDeployment forModelName( public static AiCoreDeployment forScenarioId( @Nonnull final AiCoreService service, @Nonnull final String scenarioId) { final Predicate p = deployment -> scenarioId.equals(deployment.getScenarioId()); - return new AiCoreDeployment(service, obj -> obj.getDeploymentId(p), "default"); + return new AiCoreDeployment(service, obj -> obj.getDeploymentId(service.client(), p)); } /** @@ -74,7 +86,7 @@ public static AiCoreDeployment forScenarioId( @Nonnull public static AiCoreDeployment forDeploymentId( @Nonnull final AiCoreService service, @Nonnull final String deploymentId) { - return new AiCoreDeployment(service, obj -> deploymentId, "default"); + return new AiCoreDeployment(service, obj -> deploymentId); } @Nonnull @@ -196,12 +208,13 @@ protected static boolean isDeploymentOfModel( * @throws NoSuchElementException if no deployment is found for the scenario id. */ @Nonnull - protected String getDeploymentId(@Nonnull final Predicate predicate) + protected String getDeploymentId( + @Nonnull final ApiClient client, @Nonnull final Predicate predicate) throws NoSuchElementException { final var resourceGroup = getResourceGroup(); final var deployments = - CACHE.computeIfAbsent(resourceGroup, rg -> new DeploymentApi(client()).query(rg)); + CACHE.computeIfAbsent(resourceGroup, rg -> new DeploymentApi(client).query(rg)); final var first = deployments.getResources().stream().filter(predicate).map(AiDeployment::getId).findFirst();