Watson Conversation node.js使用learning_opt_out创建工作空间

时间:2017-10-27 12:18:43

标签: javascript node.js ibm-watson watson-assistant

我正在尝试在node.js中使用learning_opt_out true创建一个新的watson-conversation工作区。 以下代码创建工作区,但learning_opt_out仍为false

你能帮忙吗?

var watson = require("watson-developer-cloud");

var conversation = new watson.ConversationV1({
  username: 'user',
  password: 'password',
  url: 'https://gateway-fra.watsonplatform.net/conversation/api/',
  version_date: '2017-05-26'
});

var workspace = {
  name: 'API test',
  description: 'Example workspace created via API.',
  language: 'de',
  learning_opt_out: 'true'
};

conversation.createWorkspace(workspace, function(err, response) {
  if (err) {
    console.error(err);
  } else {
    console.log(JSON.stringify(response, null, 2));
  }
 });

运行此代码会创建以下输出:

{
  "name": "API test",
  "created": "2017-10-27T12:16:11.170Z",
  "updated": "2017-10-27T12:16:11.170Z",
  "language": "de",
  "metadata": null,
  "description": "Example workspace created via API.",
  "workspace_id": "xxx",
  "learning_opt_out": false
}

1 个答案:

答案 0 :(得分:3)

作为you can seelearning_opt_out的参数为布尔值

  

learning_opt_out(boolean,optional):是否从中训练数据   IBM可以使用工作空间来改进常规服务。真正   表示不使用工作空间训练数据。

修改

在了解了有关此问题和参数learning_opt_out的更多内容后,我found了答案,您需要在对话服务和header以及{{1}的调用中设置一个username }}:

例如:

password

结果:

var watson = require("watson-developer-cloud");

var conversation = new watson.ConversationV1({
  username: 'user',
  password: 'pass',
  url: 'https://gateway-fra.watsonplatform.net/conversation/api/',
  version_date: '2017-05-26',
  //X-WDC-PL-OPT-OUT: true
  headers: {
       'X-Watson-Learning-Opt-Out': true
  }
});

var workspace = {
  name: 'API test',
  description: 'Example workspace created via API.',
  language: 'de',
  //'X-WDC-PL-OPT-OUT': true
};

conversation.createWorkspace(workspace, function(err, response) {
  if (err) {
    console.error(err);
  } else {
    console.log(JSON.stringify(response, null, 2));
  }
});