Skip to content

Commit

Permalink
Merged main
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesDuboisSAP committed Oct 16, 2024
1 parent 0c088a8 commit c0af7db
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 40 deletions.
38 changes: 0 additions & 38 deletions core/src/main/java/com/sap/ai/sdk/core/AiCoreDeployment.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.sap.ai.sdk.core;

import com.sap.ai.sdk.core.client.model.AiDeployment;
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationProperty;
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
import java.util.Map;
import java.util.function.Function;
import javax.annotation.Nonnull;
import lombok.AccessLevel;
Expand Down Expand Up @@ -102,40 +100,4 @@ public AiCoreDeployment withResourceGroup(@Nonnull final String resourceGroup) {
protected String getDeploymentId() {
return deploymentId.apply(this);
}

/**
* This exists because getBackendDetails() is broken
*
* @param modelName The model name.
* @param deployment The deployment.
* @return true if the deployment is of the model.
*/
protected static boolean isDeploymentOfModel(
@Nonnull final String modelName, @Nonnull final AiDeployment deployment) {
final var deploymentDetails = deployment.getDetails();
// The AI Core specification doesn't mention that this is nullable, but it can be.
// Remove this check when the specification is fixed.
if (deploymentDetails == null) {
return false;
}
final var resources = deploymentDetails.getResources();
if (resources == null) {
return false;
}
Object detailsObject = resources.getBackendDetails();
// workaround for AIWDF-2124
if (detailsObject == null) {
if (!resources.getCustomFieldNames().contains("backend_details")) {
return false;
}
detailsObject = resources.getCustomField("backend_details");
}

if (detailsObject instanceof Map<?, ?> details
&& details.get("model") instanceof Map<?, ?> model
&& model.get("name") instanceof String name) {
return modelName.equals(name);
}
return false;
}
}
39 changes: 37 additions & 2 deletions core/src/main/java/com/sap/ai/sdk/core/DeploymentCache.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.sap.ai.sdk.core;

import static com.sap.ai.sdk.core.AiCoreDeployment.isDeploymentOfModel;

import com.sap.ai.sdk.core.client.DeploymentApi;
import com.sap.ai.sdk.core.client.model.AiDeployment;
import com.sap.cloud.sdk.services.openapi.apiclient.ApiClient;
import com.sap.cloud.sdk.services.openapi.core.OpenApiRequestException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -131,4 +130,40 @@ private Optional<String> getDeploymentIdByScenario(@Nonnull final String scenari
.findFirst()
.map(AiDeployment::getId);
}

/**
* This exists because getBackendDetails() is broken
*
* @param modelName The model name.
* @param deployment The deployment.
* @return true if the deployment is of the model.
*/
protected static boolean isDeploymentOfModel(
@Nonnull final String modelName, @Nonnull final AiDeployment deployment) {
final var deploymentDetails = deployment.getDetails();
// The AI Core specification doesn't mention that this is nullable, but it can be.
// Remove this check when the specification is fixed.
if (deploymentDetails == null) {
return false;
}
final var resources = deploymentDetails.getResources();
if (resources == null) {
return false;
}
Object detailsObject = resources.getBackendDetails();
// workaround for AIWDF-2124
if (detailsObject == null) {
if (!resources.getCustomFieldNames().contains("backend_details")) {
return false;
}
detailsObject = resources.getCustomField("backend_details");
}

if (detailsObject instanceof Map<?, ?> details
&& details.get("model") instanceof Map<?, ?> model
&& model.get("name") instanceof String name) {
return modelName.equals(name);
}
return false;
}
}

0 comments on commit c0af7db

Please sign in to comment.