【发布时间】:2018-03-25 12:15:38
【问题描述】:
一旦应用程序(Java Web 应用程序)连接了一个对话,就需要传回相同的上下文。但是每次我发送输入(文本到 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]
【问题讨论】:
-
是否找到正确的对话节点,然后根据输入进行处理?你的问题不清楚。
-
@data_henrik 不,它总是去其他节点(不同)