Search in sources :

Example 31 with Context

use of com.ibm.watson.assistant.v1.model.Context in project java-sdk by watson-developer-cloud.

the class Assistant method listMentions.

/**
 * List entity mentions.
 *
 * <p>List mentions for a contextual entity. An entity mention is an occurrence of a contextual
 * entity in the context of an intent user input example.
 *
 * @param listMentionsOptions the {@link ListMentionsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link EntityMentionCollection}
 */
public ServiceCall<EntityMentionCollection> listMentions(ListMentionsOptions listMentionsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listMentionsOptions, "listMentionsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", listMentionsOptions.workspaceId());
    pathParamsMap.put("entity", listMentionsOptions.entity());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/mentions", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listMentions");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (listMentionsOptions.export() != null) {
        builder.query("export", String.valueOf(listMentionsOptions.export()));
    }
    if (listMentionsOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listMentionsOptions.includeAudit()));
    }
    ResponseConverter<EntityMentionCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<EntityMentionCollection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) EntityMentionCollection(com.ibm.watson.assistant.v1.model.EntityMentionCollection)

Example 32 with Context

use of com.ibm.watson.assistant.v1.model.Context in project java-sdk by watson-developer-cloud.

the class Assistant method message.

/**
 * Get response to user input.
 *
 * <p>Send user input to a workspace and receive a response.
 *
 * <p>**Important:** This method has been superseded by the new v2 runtime API. The v2 API offers
 * significant advantages, including ease of deployment, automatic state management, versioning,
 * and search capabilities. For more information, see the
 * [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-api-overview).
 *
 * @param messageOptions the {@link MessageOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link MessageResponse}
 */
public ServiceCall<MessageResponse> message(MessageOptions messageOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(messageOptions, "messageOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", messageOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/message", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "message");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (messageOptions.nodesVisitedDetails() != null) {
        builder.query("nodes_visited_details", String.valueOf(messageOptions.nodesVisitedDetails()));
    }
    final JsonObject contentJson = new JsonObject();
    if (messageOptions.input() != null) {
        contentJson.add("input", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.input()));
    }
    if (messageOptions.intents() != null) {
        contentJson.add("intents", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.intents()));
    }
    if (messageOptions.entities() != null) {
        contentJson.add("entities", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.entities()));
    }
    if (messageOptions.alternateIntents() != null) {
        contentJson.addProperty("alternate_intents", messageOptions.alternateIntents());
    }
    if (messageOptions.context() != null) {
        contentJson.add("context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.context()));
    }
    if (messageOptions.output() != null) {
        contentJson.add("output", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(messageOptions.output()));
    }
    if (messageOptions.userId() != null) {
        contentJson.addProperty("user_id", messageOptions.userId());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<MessageResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MessageResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) MessageResponse(com.ibm.watson.assistant.v1.model.MessageResponse) JsonObject(com.google.gson.JsonObject)

Example 33 with Context

use of com.ibm.watson.assistant.v1.model.Context in project target-java-sdk by adobe.

the class TelemetryServiceTest method testTelemetryForHybrid.

/**
 * This test is executed on-device for this Hybrid request.
 *
 * @throws NoSuchFieldException
 * @throws IOException
 */
@Test
void testTelemetryForHybrid() throws NoSuchFieldException, IOException {
    setup(true, DecisioningMethod.HYBRID, "testTelemetryForHybrid");
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).decisioningMethod(DecisioningMethod.HYBRID).build();
    targetJavaClient.getOffers(targetDeliveryRequest);
    verify(telemetryServiceSpy, times(2)).getTelemetry();
    verify(telemetryServiceSpy, times(1)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class));
    verify(telemetryServiceSpy, times(2)).addTelemetry(any(TargetDeliveryRequest.class), any(TimingTool.class), any(TargetDeliveryResponse.class), any(Double.class), any(Long.class));
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) TimingTool(com.adobe.target.edge.client.utils.TimingTool) TargetDeliveryResponse(com.adobe.target.edge.client.model.TargetDeliveryResponse) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) Test(org.junit.jupiter.api.Test)

Example 34 with Context

use of com.ibm.watson.assistant.v1.model.Context in project target-java-sdk by adobe.

the class TelemetryServiceTest method testTelemetrySentOnPrefetch.

/**
 * Check telemetryEntry in prefetch call
 *
 * @throws NoSuchFieldException
 * @throws IOException
 */
@Test
void testTelemetrySentOnPrefetch() throws NoSuchFieldException, IOException {
    setup(true, DecisioningMethod.ON_DEVICE, "testTelemetrySentOnPrefetch");
    long timestamp = System.currentTimeMillis();
    TargetService targetServiceMock = mock(TargetService.class, RETURNS_DEFAULTS);
    NotificationService notificationService = new NotificationService(targetServiceMock, clientConfig, clusterLocator);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), notificationService);
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().index(0).name("TEST_PREFETCH"))).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
    targetJavaClient.getOffers(targetDeliveryRequest);
    Telemetry telemetry = telemetryServiceSpy.getTelemetry();
    assertNotNull(telemetry);
    TelemetryEntry telemetryEntry = telemetry.getEntries().get(1);
    assertTrue(telemetryEntry.getTimestamp() > timestamp);
    assertTrue(telemetryEntry.getExecution() > 0);
    assertTrue(telemetryEntry.getRequestId().length() > 0);
    assertEquals(telemetryEntry.getFeatures().getDecisioningMethod(), "on-device");
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryEntry(com.adobe.target.delivery.v1.model.TelemetryEntry) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) Test(org.junit.jupiter.api.Test)

Example 35 with Context

use of com.ibm.watson.assistant.v1.model.Context in project target-java-sdk by adobe.

the class TelemetryServiceTest method testTelemetrySentOnExecute.

/**
 * Check telemetryEntry in execute call
 *
 * @throws NoSuchFieldException
 * @throws IOException
 */
@Test
void testTelemetrySentOnExecute() throws NoSuchFieldException, IOException {
    setup(true, DecisioningMethod.ON_DEVICE, "testTelemetrySentOnExecute");
    long timestamp = System.currentTimeMillis();
    TargetService targetServiceMock = mock(TargetService.class, RETURNS_DEFAULTS);
    NotificationService notificationService = new NotificationService(targetServiceMock, clientConfig, clusterLocator);
    FieldSetter.setField(localService, localService.getClass().getDeclaredField("notificationService"), notificationService);
    fileRuleLoader("DECISIONING_PAYLOAD_ALL_MATCHES.json", localService);
    TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder().context(new Context().channel(ChannelType.WEB)).execute(new ExecuteRequest().addMboxesItem(new MboxRequest().index(0).name("allmatches"))).prefetch(new PrefetchRequest().addMboxesItem(new MboxRequest().index(0).name("TEST_PREFETCH"))).decisioningMethod(DecisioningMethod.ON_DEVICE).build();
    targetJavaClient.getOffers(targetDeliveryRequest);
    ArgumentCaptor<TargetDeliveryRequest> captor = ArgumentCaptor.forClass(TargetDeliveryRequest.class);
    verify(targetServiceMock, timeout(1000)).executeNotificationAsync(captor.capture());
    Telemetry telemetry = telemetryServiceSpy.getTelemetry();
    assertNotNull(telemetry);
    assertEquals(telemetry.getEntries().size(), 2);
    TelemetryEntry telemetryEntry = telemetry.getEntries().get(1);
    assertTrue(telemetryEntry.getTimestamp() > timestamp);
    assertTrue(telemetryEntry.getExecution() > 0);
    assertTrue(telemetryEntry.getRequestId().length() > 0);
    assertEquals(telemetryEntry.getFeatures().getDecisioningMethod(), "on-device");
}
Also used : Context(com.adobe.target.delivery.v1.model.Context) TargetTestDeliveryRequestUtils.getContext(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext) PrefetchRequest(com.adobe.target.delivery.v1.model.PrefetchRequest) TargetTestDeliveryRequestUtils.getMboxExecuteRequest(com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest) ExecuteRequest(com.adobe.target.delivery.v1.model.ExecuteRequest) MboxRequest(com.adobe.target.delivery.v1.model.MboxRequest) TargetDeliveryRequest(com.adobe.target.edge.client.model.TargetDeliveryRequest) TelemetryEntry(com.adobe.target.delivery.v1.model.TelemetryEntry) Telemetry(com.adobe.target.delivery.v1.model.Telemetry) Test(org.junit.jupiter.api.Test)

Aggregations

Context (com.adobe.target.delivery.v1.model.Context)24 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)21 Test (org.junit.jupiter.api.Test)19 ExecuteRequest (com.adobe.target.delivery.v1.model.ExecuteRequest)18 TargetTestDeliveryRequestUtils.getContext (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getContext)17 TargetTestDeliveryRequestUtils.getMboxExecuteRequest (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getMboxExecuteRequest)15 PrefetchRequest (com.adobe.target.delivery.v1.model.PrefetchRequest)14 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 TargetDeliveryResponse (com.adobe.target.edge.client.model.TargetDeliveryResponse)13 TimingTool (com.adobe.target.edge.client.utils.TimingTool)12 MockResponse (okhttp3.mockwebserver.MockResponse)12 Test (org.testng.annotations.Test)12 HashMap (java.util.HashMap)11 Property (com.adobe.target.delivery.v1.model.Property)8 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)8 DeliveryResponse (com.adobe.target.delivery.v1.model.DeliveryResponse)6 MboxRequest (com.adobe.target.delivery.v1.model.MboxRequest)6 TelemetryEntry (com.adobe.target.delivery.v1.model.TelemetryEntry)6 TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getNoContentDeliveryResponse)6 TargetTestDeliveryRequestUtils.getTestDeliveryResponse (com.adobe.target.edge.client.utils.TargetTestDeliveryRequestUtils.getTestDeliveryResponse)6