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);
}
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);
}
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));
}
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");
}
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");
}
Aggregations