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

Watson Conversation node.js create workspace with learning_opt_out

我正在尝试在 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
}

you can see一样,learning_opt_out的参数是boolean:

learning_opt_out (boolean, optional): Whether training data from the workspace can be used by IBM for general service improvements. true indicates that workspace training data is not to be used.

编辑:

在看到更多关于这个问题和参数 learning_opt_out 的信息后,我 found 给出了答案,您需要在 Conversation 服务调用中设置一个 header 并且 usernamepassword:

例如:

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

结果:

{
  "name": "API test",
  "created": "2017-11-03T12:16:08.025Z",
  "updated": "2017-11-03T12:16:08.025Z",
  "language": "de",
  "metadata": null,
  "description": "Example workspace created via API.",
  "workspace_id": "c143cfd2-2350-491e-bc58-b9debf06e03f",
  "learning_opt_out": true
}