use of com.ibm.watson.assistant.v1.model.RuntimeIntent in project java-sdk by watson-developer-cloud.
the class ConversationTest method testSendMessage.
/**
* Test send message.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessage() throws IOException, InterruptedException {
String text = "I'd like to get insurance to for my home";
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
InputData input = new InputData.Builder(text).build();
RuntimeIntent intent = new RuntimeIntent();
intent.setIntent("turn_off");
intent.setConfidence(0.0);
RuntimeEntity entity = new RuntimeEntity();
entity.setEntity("car");
entity.setValue("ford");
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(input).addIntent(intent).addEntity(entity).alternateIntents(true).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
String expected = "{" + "\"input\":{\"text\":\"I'd like to get insurance to for my home\"}," + "\"intents\":[{\"confidence\":0.0,\"intent\":\"turn_off\"}]," + "\"entities\":[{\"value\":\"ford\",\"entity\":\"car\"}]," + "\"alternate_intents\":true" + "}";
JsonParser parser = new JsonParser();
JsonObject expectedObj = parser.parse(expected).getAsJsonObject();
JsonObject actualObj = parser.parse(request.getBody().readUtf8()).getAsJsonObject();
assertTrue(expectedObj.equals(actualObj));
assertEquals(serviceResponse, mockResponse);
}
use of com.ibm.watson.assistant.v1.model.RuntimeIntent in project java-sdk by watson-developer-cloud.
the class AssistantTest method testSendMessage.
/**
* Test send message.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessage() throws IOException, InterruptedException {
String text = "I'd like to get insurance to for my home";
MessageResponse mockResponse = loadFixture(FIXTURE, MessageResponse.class);
server.enqueue(jsonResponse(mockResponse));
InputData input = new InputData.Builder(text).build();
RuntimeIntent intent = new RuntimeIntent();
intent.setIntent("turn_off");
intent.setConfidence(0.0);
RuntimeEntity entity = new RuntimeEntity();
entity.setEntity("car");
entity.setValue("ford");
MessageOptions options = new MessageOptions.Builder(WORKSPACE_ID).input(input).addIntent(intent).addEntity(entity).alternateIntents(true).build();
// execute first request
MessageResponse serviceResponse = service.message(options).execute();
// first request
RecordedRequest request = server.takeRequest();
String path = StringUtils.join(PATH_MESSAGE, "?", VERSION, "=2018-02-16");
assertEquals(path, request.getPath());
assertArrayEquals(new String[] { "Do you want to get a quote?" }, serviceResponse.getOutput().getText().toArray(new String[0]));
assertEquals(request.getMethod(), "POST");
assertNotNull(request.getHeader(HttpHeaders.AUTHORIZATION));
String expected = "{" + "\"input\":{\"text\":\"I'd like to get insurance to for my home\"}," + "\"intents\":[{\"confidence\":0.0,\"intent\":\"turn_off\"}]," + "\"entities\":[{\"value\":\"ford\",\"entity\":\"car\"}]," + "\"alternate_intents\":true" + "}";
JsonParser parser = new JsonParser();
JsonObject expectedObj = parser.parse(expected).getAsJsonObject();
JsonObject actualObj = parser.parse(request.getBody().readUtf8()).getAsJsonObject();
assertTrue(expectedObj.equals(actualObj));
assertEquals(serviceResponse, mockResponse);
}
use of com.ibm.watson.assistant.v1.model.RuntimeIntent in project java-sdk by watson-developer-cloud.
the class AssistantTest method testMessageStatelessWOptions.
// Test the messageStateless operation with a valid options model parameter
@Test
public void testMessageStatelessWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"output\": {\"generic\": [{\"response_type\": \"option\", \"title\": \"title\", \"description\": \"description\", \"preference\": \"dropdown\", \"options\": [{\"label\": \"label\", \"value\": {\"input\": {\"message_type\": \"text\", \"text\": \"text\", \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}], \"suggestion_id\": \"suggestionId\", \"attachments\": [{\"url\": \"url\", \"media_type\": \"mediaType\"}], \"options\": {\"restart\": false, \"alternate_intents\": false, \"spelling\": {\"suggestions\": false, \"auto_correct\": false}, \"debug\": false, \"return_context\": false, \"export\": false}}}}], \"channels\": [{\"channel\": \"channel\"}]}], \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}], \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"debug\": {\"nodes_visited\": [{\"dialog_node\": \"dialogNode\", \"title\": \"title\", \"conditions\": \"conditions\"}], \"log_messages\": [{\"level\": \"info\", \"message\": \"message\", \"code\": \"code\", \"source\": {\"type\": \"dialog_node\", \"dialog_node\": \"dialogNode\"}}], \"branch_exited\": true, \"branch_exited_reason\": \"completed\"}, \"user_defined\": {\"mapKey\": \"anyValue\"}, \"spelling\": {\"text\": \"text\", \"original_text\": \"originalText\", \"suggested_text\": \"suggestedText\"}}, \"context\": {\"global\": {\"system\": {\"timezone\": \"timezone\", \"user_id\": \"userId\", \"turn_count\": 9, \"locale\": \"en-us\", \"reference_time\": \"referenceTime\", \"session_start_time\": \"sessionStartTime\", \"state\": \"state\", \"skip_user_input\": false}, \"session_id\": \"sessionId\"}, \"skills\": {\"mapKey\": {\"user_defined\": {\"mapKey\": {\"anyKey\": \"anyValue\"}}, \"system\": {\"state\": \"state\"}}}, \"integrations\": {\"mapKey\": \"anyValue\"}}, \"user_id\": \"userId\"}";
String messageStatelessPath = "/v2/assistants/testString/message";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the RuntimeIntent model
RuntimeIntent runtimeIntentModel = new RuntimeIntent.Builder().intent("testString").confidence(Double.valueOf("72.5")).build();
// Construct an instance of the CaptureGroup model
CaptureGroup captureGroupModel = new CaptureGroup.Builder().group("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).build();
// Construct an instance of the RuntimeEntityInterpretation model
RuntimeEntityInterpretation runtimeEntityInterpretationModel = new RuntimeEntityInterpretation.Builder().calendarType("testString").datetimeLink("testString").festival("testString").granularity("day").rangeLink("testString").rangeModifier("testString").relativeDay(Double.valueOf("72.5")).relativeMonth(Double.valueOf("72.5")).relativeWeek(Double.valueOf("72.5")).relativeWeekend(Double.valueOf("72.5")).relativeYear(Double.valueOf("72.5")).specificDay(Double.valueOf("72.5")).specificDayOfWeek("testString").specificMonth(Double.valueOf("72.5")).specificQuarter(Double.valueOf("72.5")).specificYear(Double.valueOf("72.5")).numericValue(Double.valueOf("72.5")).subtype("testString").partOfDay("testString").relativeHour(Double.valueOf("72.5")).relativeMinute(Double.valueOf("72.5")).relativeSecond(Double.valueOf("72.5")).specificHour(Double.valueOf("72.5")).specificMinute(Double.valueOf("72.5")).specificSecond(Double.valueOf("72.5")).timezone("testString").build();
// Construct an instance of the RuntimeEntityAlternative model
RuntimeEntityAlternative runtimeEntityAlternativeModel = new RuntimeEntityAlternative.Builder().value("testString").confidence(Double.valueOf("72.5")).build();
// Construct an instance of the RuntimeEntityRole model
RuntimeEntityRole runtimeEntityRoleModel = new RuntimeEntityRole.Builder().type("date_from").build();
// Construct an instance of the RuntimeEntity model
RuntimeEntity runtimeEntityModel = new RuntimeEntity.Builder().entity("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).value("testString").confidence(Double.valueOf("72.5")).groups(new java.util.ArrayList<CaptureGroup>(java.util.Arrays.asList(captureGroupModel))).interpretation(runtimeEntityInterpretationModel).alternatives(new java.util.ArrayList<RuntimeEntityAlternative>(java.util.Arrays.asList(runtimeEntityAlternativeModel))).role(runtimeEntityRoleModel).build();
// Construct an instance of the MessageInputAttachment model
MessageInputAttachment messageInputAttachmentModel = new MessageInputAttachment.Builder().url("testString").mediaType("testString").build();
// Construct an instance of the MessageInputOptionsSpelling model
MessageInputOptionsSpelling messageInputOptionsSpellingModel = new MessageInputOptionsSpelling.Builder().suggestions(true).autoCorrect(true).build();
// Construct an instance of the MessageInputOptionsStateless model
MessageInputOptionsStateless messageInputOptionsStatelessModel = new MessageInputOptionsStateless.Builder().restart(false).alternateIntents(false).spelling(messageInputOptionsSpellingModel).debug(false).build();
// Construct an instance of the MessageInputStateless model
MessageInputStateless messageInputStatelessModel = new MessageInputStateless.Builder().messageType("text").text("testString").intents(new java.util.ArrayList<RuntimeIntent>(java.util.Arrays.asList(runtimeIntentModel))).entities(new java.util.ArrayList<RuntimeEntity>(java.util.Arrays.asList(runtimeEntityModel))).suggestionId("testString").attachments(new java.util.ArrayList<MessageInputAttachment>(java.util.Arrays.asList(messageInputAttachmentModel))).options(messageInputOptionsStatelessModel).build();
// Construct an instance of the MessageContextGlobalSystem model
MessageContextGlobalSystem messageContextGlobalSystemModel = new MessageContextGlobalSystem.Builder().timezone("testString").userId("testString").turnCount(Long.valueOf("26")).locale("en-us").referenceTime("testString").sessionStartTime("testString").state("testString").skipUserInput(true).build();
// Construct an instance of the MessageContextGlobalStateless model
MessageContextGlobalStateless messageContextGlobalStatelessModel = new MessageContextGlobalStateless.Builder().system(messageContextGlobalSystemModel).sessionId("testString").build();
// Construct an instance of the MessageContextSkillSystem model
MessageContextSkillSystem messageContextSkillSystemModel = new MessageContextSkillSystem.Builder().state("testString").add("foo", "testString").build();
// Construct an instance of the MessageContextSkill model
MessageContextSkill messageContextSkillModel = new MessageContextSkill.Builder().userDefined(new java.util.HashMap<String, Object>() {
{
put("foo", TestUtilities.createMockMap());
}
}).system(messageContextSkillSystemModel).build();
// Construct an instance of the MessageContextStateless model
MessageContextStateless messageContextStatelessModel = new MessageContextStateless.Builder().global(messageContextGlobalStatelessModel).skills(new java.util.HashMap<String, MessageContextSkill>() {
{
put("foo", messageContextSkillModel);
}
}).integrations(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).build();
// Construct an instance of the MessageStatelessOptions model
MessageStatelessOptions messageStatelessOptionsModel = new MessageStatelessOptions.Builder().assistantId("testString").input(messageInputStatelessModel).context(messageContextStatelessModel).userId("testString").build();
// Invoke messageStateless() with a valid options model and verify the result
Response<MessageResponseStateless> response = assistantService.messageStateless(messageStatelessOptionsModel).execute();
assertNotNull(response);
MessageResponseStateless responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, messageStatelessPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.assistant.v1.model.RuntimeIntent in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testSendMessages.
/**
* Test send messages.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessages() throws InterruptedException {
final String[] messages = new String[] { "turn ac on", "turn right", "no", "yes" };
Context context = null;
for (final String message : messages) {
MessageOptions request = new MessageOptions.Builder(workspaceId).input(new InputData.Builder(message).build()).alternateIntents(true).context(context).nodesVisitedDetails(true).build();
if (message.equals("yes")) {
RuntimeIntent offTopic = new RuntimeIntent();
offTopic.setIntent("off_topic");
offTopic.setConfidence(1.0);
request = request.newBuilder().addIntent(offTopic).build();
}
MessageResponse response = service.message(request).execute();
assertMessageFromService(response);
assertNotNull(response.getOutput().getNodesVisitedDetails());
for (RuntimeEntity entity : response.getEntities()) {
assertNotNull(entity.getGroups());
}
context = new Context();
context.putAll(response.getContext());
Thread.sleep(500);
}
}
use of com.ibm.watson.assistant.v1.model.RuntimeIntent in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT method testSendMessages.
/**
* Test send messages.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void testSendMessages() throws InterruptedException {
final String[] messages = new String[] { "turn ac on", "turn right", "no", "yes" };
Context context = null;
for (final String message : messages) {
MessageOptions request = new MessageOptions.Builder(workspaceId).input(new InputData.Builder(message).build()).alternateIntents(true).context(context).nodesVisitedDetails(true).build();
if (message.equals("yes")) {
RuntimeIntent offTopic = new RuntimeIntent();
offTopic.setIntent("off_topic");
offTopic.setConfidence(1.0);
request = request.newBuilder().addIntent(offTopic).build();
}
MessageResponse response = service.message(request).execute();
assertMessageFromService(response);
assertNotNull(response.getOutput().getNodesVisitedDetails());
for (RuntimeEntity entity : response.getEntities()) {
assertNotNull(entity.getGroups());
}
context = new Context();
context.putAll(response.getContext());
Thread.sleep(500);
}
}
Aggregations