Search in sources :

Example 1 with OutputData

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

the class AssistantExample method main.

public static void main(String[] args) throws Exception {
    Assistant service = new Assistant("2018-02-16");
    service.setUsernameAndPassword("<username>", "<password>");
    InputData input = new InputData.Builder("Hi").build();
    MessageOptions options = new MessageOptions.Builder("<workspaceId>").input(input).build();
    // sync
    MessageResponse response = service.message(options).execute();
    System.out.println(response);
    // async
    service.message(options).enqueue(new ServiceCallback<MessageResponse>() {

        @Override
        public void onResponse(MessageResponse response) {
            System.out.println(response);
        }

        @Override
        public void onFailure(Exception e) {
        }
    });
    // rx callback
    service.message(options).rx().thenApply(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx async callback
    service.message(options).rx().thenApplyAsync(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx sync
    try {
        MessageResponse rxMessageResponse = service.message(options).rx().get();
        System.out.println(rxMessageResponse);
    } catch (Exception ex) {
    // Handle exception
    }
}
Also used : MessageResponse(com.ibm.watson.developer_cloud.assistant.v1.model.MessageResponse) CompletableFuture(jersey.repackaged.jsr166e.CompletableFuture) MessageOptions(com.ibm.watson.developer_cloud.assistant.v1.model.MessageOptions) Assistant(com.ibm.watson.developer_cloud.assistant.v1.Assistant) OutputData(com.ibm.watson.developer_cloud.assistant.v1.model.OutputData)

Example 2 with OutputData

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

the class AssistantServiceIT method testExample.

/**
 * Test Example.
 */
@Test
public void testExample() {
    InputData input = new InputData.Builder("Hi").build();
    MessageOptions options = new MessageOptions.Builder(workspaceId).input(input).build();
    // sync
    MessageResponse response = service.message(options).execute();
    System.out.println(response);
    // async
    service.message(options).enqueue(new ServiceCallback<MessageResponse>() {

        @Override
        public void onResponse(MessageResponse response) {
            System.out.println(response);
        }

        @Override
        public void onFailure(Exception e) {
        }
    });
    // rx callback
    service.message(options).rx().thenApply(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx async callback
    service.message(options).rx().thenApplyAsync(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx sync
    try {
        MessageResponse rxMessageResponse = service.message(options).rx().get();
        System.out.println(rxMessageResponse);
    } catch (Exception ex) {
    // Handle exception
    }
}
Also used : CompletableFuture(jersey.repackaged.jsr166e.CompletableFuture) MessageOptions(com.ibm.watson.developer_cloud.assistant.v1.model.MessageOptions) MessageResponse(com.ibm.watson.developer_cloud.assistant.v1.model.MessageResponse) OutputData(com.ibm.watson.developer_cloud.assistant.v1.model.OutputData) InputData(com.ibm.watson.developer_cloud.assistant.v1.model.InputData) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 3 with OutputData

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

the class ConversationServiceIT method testExample.

/**
 * Test Example.
 */
@Test
public void testExample() {
    // Conversation service = new Conversation(Conversation.VERSION_DATE_2017_05_26);
    // service.setUsernameAndPassword("<username>", "<password>");
    InputData input = new InputData.Builder("Hi").build();
    MessageOptions options = new MessageOptions.Builder(workspaceId).input(input).build();
    // sync
    MessageResponse response = service.message(options).execute();
    System.out.println(response);
    // async
    service.message(options).enqueue(new ServiceCallback<MessageResponse>() {

        @Override
        public void onResponse(MessageResponse response) {
            System.out.println(response);
        }

        @Override
        public void onFailure(Exception e) {
        }
    });
    // rx callback
    service.message(options).rx().thenApply(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx async callback
    service.message(options).rx().thenApplyAsync(new CompletableFuture.Fun<MessageResponse, OutputData>() {

        @Override
        public OutputData apply(MessageResponse message) {
            return message.getOutput();
        }
    }).thenAccept(new CompletableFuture.Action<OutputData>() {

        @Override
        public void accept(OutputData output) {
            System.out.println(output);
        }
    });
    // rx sync
    try {
        MessageResponse rxMessageResponse = service.message(options).rx().get();
        System.out.println(rxMessageResponse);
    } catch (Exception ex) {
    // Handle exception
    }
}
Also used : CompletableFuture(jersey.repackaged.jsr166e.CompletableFuture) MessageOptions(com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions) MessageResponse(com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse) OutputData(com.ibm.watson.developer_cloud.conversation.v1.model.OutputData) InputData(com.ibm.watson.developer_cloud.conversation.v1.model.InputData) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Aggregations

CompletableFuture (jersey.repackaged.jsr166e.CompletableFuture)3 MessageOptions (com.ibm.watson.developer_cloud.assistant.v1.model.MessageOptions)2 MessageResponse (com.ibm.watson.developer_cloud.assistant.v1.model.MessageResponse)2 OutputData (com.ibm.watson.developer_cloud.assistant.v1.model.OutputData)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)2 Test (org.junit.Test)2 Assistant (com.ibm.watson.developer_cloud.assistant.v1.Assistant)1 InputData (com.ibm.watson.developer_cloud.assistant.v1.model.InputData)1 InputData (com.ibm.watson.developer_cloud.conversation.v1.model.InputData)1 MessageOptions (com.ibm.watson.developer_cloud.conversation.v1.model.MessageOptions)1 MessageResponse (com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse)1 OutputData (com.ibm.watson.developer_cloud.conversation.v1.model.OutputData)1