LoginSignup
1
2

More than 5 years have passed since last update.

IBM Watson Assistant 2018-07-10 を Java SDK から呼んでみる。

Last updated at Posted at 2018-07-19

Watson Assistant 2018-07-10 では、レスポンスのタイプに「Option」などを指定できるようになりました。「Option」は、HTMLでいうラジオボタンのようなもので三択や四択といった選択肢を簡単に作ることができる機能です。

それを Watson API Java SDKから呼ぶとどうなるのか?を試してみました。
結論からいうと執筆時点のSDKでは新しい機能にまだ対応できていないようです。従来は text[] として返ってきたところが、generic として返ってくるようです。
生のJSONをパースしてやる必要がありそうです。

■画像

assistant01.png

■参照(執筆時現在、ページ下部から「English」を設定しないと読めません)

■API Document

■コード


        String version = "2018-07-10";
        String username = "xxx";
        String password = "xxx";

        String workspaceId = "xxx";

        Assistant service = new Assistant(version);
        service.setUsernameAndPassword(username, password);

        InputData input = new InputData.Builder("Hi").build();

        // MessageOptions options = new
        // MessageOptions.Builder(workspaceId).input(input).build();
        MessageOptions options = new MessageOptions.Builder(workspaceId).build();

        // sync
        MessageResponse response = service.message(options).execute();
        System.err.println(response);

        System.err.println("---");

        System.err.println(response.getOutput().getText());


■結果

{
  "output": {
    "generic": [
      {
        "title": "",
        "options": [
          {
            "label": "Value1",
            "value": {
              "input": {
                "text": "value1"
              }
            }
          },
          {
            "label": "Value2",
            "value": {
              "input": {
                "text": "value2"
              }
            }
          },
          {
            "label": "Value3",
            "value": {
              "input": {
                "text": "value3"
              }
            }
          }
        ],
        "response_type": "option"
      }
    ],
    "text": [],
    "nodes_visited": [
      "ようこそ"
    ],
    "log_messages": []
  },
  "input": {},
  "intents": [],
  "entities": [],
  "context": {
    "conversation_id": "xxx",
    "system": {
      "dialog_stack": [
        {
          "dialog_node": "root"
        }
      ],
      "dialog_turn_counter": 1.0,
      "dialog_request_counter": 1.0,
      "branch_exited": true,
      "branch_exited_reason": "completed"
    }
  }
}
---
[]
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2