Search in sources :

Example 1 with LocalExplainer

use of org.kie.kogito.explainability.local.LocalExplainer in project kogito-apps by kiegroup.

the class LocalExplainerServiceHandler method explainAsyncWithResults.

/**
 * Requests calculation of an explanation decorated with both "success" and "failure" result handlers.
 * See:
 * - {@link LocalExplainer#explainAsync}
 * - {@link LocalExplainerServiceHandler#createSucceededResult(BaseExplainabilityRequest, Object)}
 * - {@link LocalExplainerServiceHandler#createFailedResult(BaseExplainabilityRequest, Throwable)}
 *
 * @param request The explanation request.
 * @param intermediateResultsConsumer A consumer for intermediate results provided by the explainer.
 * @return
 */
default CompletableFuture<BaseExplainabilityResult> explainAsyncWithResults(R request, Consumer<BaseExplainabilityResult> intermediateResultsConsumer) {
    Prediction prediction = getPrediction(request);
    PredictionProvider predictionProvider = getPredictionProvider(request);
    return explainAsync(prediction, predictionProvider, s -> intermediateResultsConsumer.accept(createIntermediateResult(request, s))).thenApply(input -> createSucceededResult(request, input)).exceptionally(e -> createFailedResult(request, e));
}
Also used : Consumer(java.util.function.Consumer) BaseExplainabilityRequest(org.kie.kogito.explainability.api.BaseExplainabilityRequest) LocalExplainer(org.kie.kogito.explainability.local.LocalExplainer) Prediction(org.kie.kogito.explainability.model.Prediction) CompletableFuture(java.util.concurrent.CompletableFuture) BaseExplainabilityResult(org.kie.kogito.explainability.api.BaseExplainabilityResult) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider) Prediction(org.kie.kogito.explainability.model.Prediction) PredictionProvider(org.kie.kogito.explainability.model.PredictionProvider)

Aggregations

CompletableFuture (java.util.concurrent.CompletableFuture)1 Consumer (java.util.function.Consumer)1 BaseExplainabilityRequest (org.kie.kogito.explainability.api.BaseExplainabilityRequest)1 BaseExplainabilityResult (org.kie.kogito.explainability.api.BaseExplainabilityResult)1 LocalExplainer (org.kie.kogito.explainability.local.LocalExplainer)1 Prediction (org.kie.kogito.explainability.model.Prediction)1 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)1