ibm-cloud - MessageResponse 在 Watson Conversation 中返回空指针

标签 ibm-cloud ibm-watson chatbot watson-conversation

MessageResponse 给出 NullPointerException

ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2016_09_20);
// Credentials of Workspace of Conversation
service.setApiKey("API_KEY");
service.setUsernameAndPassword("USERNAME", "PASSWORD");
MessageRequest newMessage = new MessageRequest.Builder()
  .inputText(request.getQuery())
  .build();

// Workspace ID of Conversation current workspace
String workspaceId = "WORKSPACEID";
service.setSkipAuthentication(true);
MessageResponse response = service.message(workspaceId, newMessage)
  .execute();

最佳答案

根据 IBM 开发人员 (@German) 的说法:“Watson 服务当前使用基本身份验证,因此您将使用用户名和密码而不是 api_key。为了获取凭据,您需要绑定(bind)要使用的服务(例如,问题和答案)到 Bluemix 应用程序。”

检查以下示例。

尝试使用 Java SDK 中的以下代码:

ConversationService service = new ConversationService(ConversationService.VERSION_DATE_2017_05_26);
service.setUsernameAndPassword("<username>", "<password>"); //Please make sure if this username and password is the Service Credentials from the Service that you have created to use Conversation

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);

其他示例:

MessageRequest newMessage = new MessageRequest.Builder().inputText(input).context(context).build();

MessageResponse response = service.message(WORKSPACE_ID,newMessage).execute();

context = response.getContext();    
System.out.println(response);
  • 您可以查看官方 example使用 Watson Conversation。
  • 请参阅使用 Watson 服务的入门指南(第 5 步)here .

关于ibm-cloud - MessageResponse 在 Watson Conversation 中返回空指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46095284/

相关文章:

python - 属性错误: “' ChatBot' object has no attribute 'trains' ”

terraform - 如何使用自定义镜像创建 IBM Cloud VSI

java - 解析 'parameters' JSON Watson 视觉识别时出错

mysql - 如何在不将实例绑定(bind)到 Bluemix 上的应用程序的情况下获取在 IBM Bluemix 上创建的服务实例的服务凭证?

speech-recognition - IBM Watson 支持 "Speaker diarization"/"Speaker Recognition"吗?

node.js - 如何解决此错误: Cannot find module 'ibm-watson'

python - 我如何在Python中使用chatgpt将我的聊天机器人从 "text-davinci-003"更新到 "gpt-3.5-turbo"

bots - 底部压力 : Custom Content Type and Custom Rendering

python - WatsonException : Error: invalid request: 'text' is in invalid format, 代码:400

java - Bluemix - Java 应用程序 - 如何为 Unlimited JCE Strength 打补丁?