gpt4 book ai didi

java - 使用 java 获取 Watson 对话的所有输出

转载 作者:行者123 更新时间:2023-11-30 06:27:31 26 4
gpt4 key购买 nike

如果我有一个 IBM bluemix Watson 对话对话框输出 JSON,如下所示:

"output": {
"text": {
"values": [
"What is your name?",
"Name of the person?",
"Please specify the name of the person."
],
"selection_policy": "random",
"append": true
}
}

如何从输出响应中获取所有建议?

最佳答案

您可以使用上下文变量来保存用户所说的内容,使用 <? input.text ?> 。尝试遵循这个简单的例子:

在上面这个Node中创建一个子节点,并添加:

{
"context": {
"userTypes": "<? input.text ?>"
},
"output": {
"text": {
"values": [
"All you said here: $userTypes."
],
"selection_policy": "sequential"
}
}
}

因此,在您的 Java 示例中,您可以使用以下方法获取此上下文变量的值:

private Map<String, Object> context = new HashMap<>();

ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_09_20);
service.setUsernameAndPassword('Your Watson service UserName', 'Your watson service PassWord');
MessageRequest newMessage = new MessageRequest.Builder().inputText(inputmessage).context(context).build();
MessageResponse response = service.message('Your Workspace Id', newMessage).execute();

//Passing Context of last conversation
if(response.getContext() !=null)
{
context.clear();

context = response.getContext();

}

关于java - 使用 java 获取 Watson 对话的所有输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46847072/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com