Search in sources :

Example 6 with ModelIdentifier

use of org.kie.kogito.explainability.api.ModelIdentifier in project kogito-apps by kiegroup.

the class ExplainabilityApiV1Test method testGetCounterfactualResultsWhenExecutionDoesExist.

@Test
public void testGetCounterfactualResultsWhenExecutionDoesExist() {
    NamedTypedValue goal = buildGoalUnit("unit", "string", new TextNode("hello"));
    CounterfactualSearchDomain searchDomain = buildSearchDomainUnit("unit", "string", new CounterfactualDomainCategorical(List.of(new TextNode("hello"), new TextNode("goodbye"))));
    when(trustyService.getCounterfactualRequest(anyString(), anyString())).thenReturn(new CounterfactualExplainabilityRequest(EXECUTION_ID, SERVICE_URL, new ModelIdentifier("resourceType", "resourceIdentifier"), COUNTERFACTUAL_ID, Collections.emptyList(), List.of(goal), List.of(searchDomain), MAX_RUNNING_TIME_SECONDS));
    Response response = explainabilityEndpoint.getCounterfactualDetails(EXECUTION_ID, COUNTERFACTUAL_ID);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Object entity = response.getEntity();
    assertNotNull(entity);
    assertTrue(entity instanceof CounterfactualResultsResponse);
    CounterfactualResultsResponse resultsResponse = (CounterfactualResultsResponse) entity;
    assertEquals(EXECUTION_ID, resultsResponse.getExecutionId());
    assertEquals(COUNTERFACTUAL_ID, resultsResponse.getCounterfactualId());
    assertEquals(MAX_RUNNING_TIME_SECONDS, resultsResponse.getMaxRunningTimeSeconds());
    assertEquals(1, resultsResponse.getGoals().size());
    assertEquals(goal, resultsResponse.getGoals().iterator().next());
    assertEquals(1, resultsResponse.getSearchDomains().size());
    assertEquals(searchDomain, resultsResponse.getSearchDomains().iterator().next());
    assertTrue(resultsResponse.getSolutions().isEmpty());
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) CounterfactualRequestResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse) Response(javax.ws.rs.core.Response) CounterfactualResultsResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualResultsResponse) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) ModelIdentifier(org.kie.kogito.explainability.api.ModelIdentifier) TextNode(com.fasterxml.jackson.databind.node.TextNode) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) CounterfactualResultsResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualResultsResponse) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Example 7 with ModelIdentifier

use of org.kie.kogito.explainability.api.ModelIdentifier in project kogito-apps by kiegroup.

the class ExplainabilityApiV1Test method testGetAllCounterfactualsWhenExecutionDoesExist.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testGetAllCounterfactualsWhenExecutionDoesExist() {
    when(trustyService.getCounterfactualRequests(anyString())).thenReturn(List.of(new CounterfactualExplainabilityRequest(EXECUTION_ID, SERVICE_URL, new ModelIdentifier("resourceType", "resourceIdentifier"), COUNTERFACTUAL_ID, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), MAX_RUNNING_TIME_SECONDS)));
    Response response = explainabilityEndpoint.getAllCounterfactualsSummary(EXECUTION_ID);
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Object entity = response.getEntity();
    assertNotNull(entity);
    assertTrue(entity instanceof List);
    List<CounterfactualRequestResponse> counterfactualRequestResponse = (List) entity;
    assertEquals(1, counterfactualRequestResponse.size());
    CounterfactualRequestResponse counterfactual = counterfactualRequestResponse.get(0);
    assertEquals(EXECUTION_ID, counterfactual.getExecutionId());
    assertEquals(COUNTERFACTUAL_ID, counterfactual.getCounterfactualId());
    assertEquals(MAX_RUNNING_TIME_SECONDS, counterfactual.getMaxRunningTimeSeconds());
}
Also used : CounterfactualExplainabilityRequest(org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest) CounterfactualRequestResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse) Response(javax.ws.rs.core.Response) CounterfactualResultsResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualResultsResponse) ModelIdentifier(org.kie.kogito.explainability.api.ModelIdentifier) List(java.util.List) CounterfactualRequestResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse) Test(org.junit.jupiter.api.Test)

Example 8 with ModelIdentifier

use of org.kie.kogito.explainability.api.ModelIdentifier in project kogito-apps by kiegroup.

the class ExplainabilityRequestProducerTest method test.

@Test
void test() {
    AssertSubscriber<String> subscriber = AssertSubscriber.create(1);
    ExplainabilityRequestProducer producer = new ExplainabilityRequestProducer();
    producer.getEventPublisher().subscribe(subscriber);
    producer.sendEvent(new LIMEExplainabilityRequest("executionId", "http://localhost:8080/model", new ModelIdentifier("dmn", "modelNamespace:model"), Collections.emptyList(), Collections.emptyList()));
    assertEquals(1, subscriber.getItems().size());
}
Also used : LIMEExplainabilityRequest(org.kie.kogito.explainability.api.LIMEExplainabilityRequest) ModelIdentifier(org.kie.kogito.explainability.api.ModelIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)8 ModelIdentifier (org.kie.kogito.explainability.api.ModelIdentifier)8 CounterfactualExplainabilityRequest (org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest)5 Response (javax.ws.rs.core.Response)4 CounterfactualRequestResponse (org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse)4 CounterfactualResultsResponse (org.kie.kogito.trusty.service.common.responses.CounterfactualResultsResponse)4 CounterfactualSearchDomain (org.kie.kogito.explainability.api.CounterfactualSearchDomain)3 LIMEExplainabilityRequest (org.kie.kogito.explainability.api.LIMEExplainabilityRequest)3 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 CounterfactualDomainCategorical (org.kie.kogito.explainability.api.CounterfactualDomainCategorical)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 List (java.util.List)1 BaseExplainabilityResult (org.kie.kogito.explainability.api.BaseExplainabilityResult)1 CounterfactualDomainRange (org.kie.kogito.explainability.api.CounterfactualDomainRange)1 CounterfactualExplainabilityResult (org.kie.kogito.explainability.api.CounterfactualExplainabilityResult)1 CounterfactualSearchDomainUnitValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue)1 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)1