Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically set capabilities endpoint based on configuration #281

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ public Model getModelInfo() {
return modelInfoConverter.apply(pipeline);
}

public ShapleyLoadOption getEnabledShapleyTypes() {
return enabledShapleyTypes;
}

/**
* Method to load mojo pipelines for shapley scoring based on configuration
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import ai.h2o.mojos.deploy.common.rest.model.ScoreResponse;
import ai.h2o.mojos.deploy.common.transform.MojoScorer;
import ai.h2o.mojos.deploy.common.transform.SampleRequestBuilder;
import ai.h2o.mojos.deploy.common.transform.ShapleyLoadOption;
import com.google.common.base.Strings;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
Expand All @@ -24,13 +25,13 @@
@Controller
public class ModelsApiController implements ModelApi {

private static final List<CapabilityType> SUPPORTED_CAPABILITIES
= Arrays.asList(CapabilityType.SCORE, CapabilityType.CONTRIBUTION_TRANSFORMED);
private static final Logger log = LoggerFactory.getLogger(ModelsApiController.class);

private final MojoScorer scorer;
private final SampleRequestBuilder sampleRequestBuilder;

private final List<CapabilityType> supportedCapabilities;
nkpng2k marked this conversation as resolved.
Show resolved Hide resolved

/**
* Simple Api controller. Inherits from {@link ModelApi}, which controls global, expected request
* mappings for the rest service.
Expand All @@ -44,6 +45,7 @@ public class ModelsApiController implements ModelApi {
public ModelsApiController(MojoScorer scorer, SampleRequestBuilder sampleRequestBuilder) {
this.scorer = scorer;
this.sampleRequestBuilder = sampleRequestBuilder;
this.supportedCapabilities = setSupportedCapabilities();
}

@Override
Expand All @@ -58,7 +60,7 @@ public ResponseEntity<String> getModelId() {

@Override
public ResponseEntity<List<CapabilityType>> getCapabilities() {
return ResponseEntity.ok(SUPPORTED_CAPABILITIES);
return ResponseEntity.ok(supportedCapabilities);
}

@Override
Expand Down Expand Up @@ -116,4 +118,26 @@ public ResponseEntity<ContributionResponse> getContribution(
public ResponseEntity<ScoreRequest> getSampleRequest() {
return ResponseEntity.ok(sampleRequestBuilder.build(scorer.getPipeline().getInputMeta()));
}

private List<CapabilityType> setSupportedCapabilities() {
List<CapabilityType> capabilityTypes = new ArrayList<>();
capabilityTypes.add(CapabilityType.SCORE);
ShapleyLoadOption enabledShapleyTypes = scorer.getEnabledShapleyTypes();
switch (enabledShapleyTypes) {
case ALL:
capabilityTypes.add(CapabilityType.CONTRIBUTION_ORIGINAL);
capabilityTypes.add(CapabilityType.CONTRIBUTION_TRANSFORMED);
break;
case ORIGINAL:
capabilityTypes.add(CapabilityType.CONTRIBUTION_ORIGINAL);
break;
case TRANSFORMED:
capabilityTypes.add(CapabilityType.CONTRIBUTION_TRANSFORMED);
break;
case NONE:
default:
break;
}
return capabilityTypes;
nkpng2k marked this conversation as resolved.
Show resolved Hide resolved
}
}