每次输入Watson Conversation(新名称Watson Assistant)都会改变意图?

时间:2018-03-25 12:15:38

标签: java watson-conversation

一旦应用程序(Java Web app)连接了对话,就需要传回相同的上下文。但是每当我发送输入(文本到Watson)时,意图就会改变(不同的节点),它不会保持相同的意图。为什么? 我哪里弄错了?

public class TestConversation {

    public static void main(String[] args) {
        BufferedReader br = null;
        MessageResponse response = null;
        Map context = new HashMap();

        try {
            br = new BufferedReader(new InputStreamReader(System.in));

            String userName = br.readLine();
            // Add userName to context to be used by Conversation.
            context.put("userName", userName);

            while (true) {
                String input = br.readLine();
                response = conversationAPI(input, context);
                System.out.println("Watson Response: " + response.getText().get(0));
                context = response.getContext();
                System.out.println("———–");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static MessageResponse conversationAPI(String input, Map context) {
        ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_07_11);

        // Credentials of Workspace of Conversation
        service.setUsernameAndPassword("******************", "****************");
        MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();

        // Workspace ID of Conversation current workspace
        String workspaceId = "******************";
        MessageResponse response = service.message(workspaceId, newMessage).execute();
        return response;
    }

}

[附上代码截图。] [1]

[]:https://i.stack.imgur.com/bym6u.png

1 个答案:

答案 0 :(得分:1)

将分析您发送回会话的每个输入,然后返回意图+实体以获取所写内容。

如果正确设置了对话框流以忽略它,则应该没有任何影响。

如果你想强制它,你可以发送intents[]entities[]。它将禁用检查并假设这些是找到的值。