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

问题描述 投票:3回答:1

我正在尝试使用node.js中的learning_opt_out true创建一个新的watson对话工作区。以下代码创建工作区,但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
}
javascript node.js ibm-watson watson-assistant
1个回答
3
投票

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

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

编辑:

在看了更多关于这个问题和参数learning_opt_out之后,我found答案,你需要在你的对话服务和你的headerusername的调用中设置一个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));
  }
});

结果如下:

{
  "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
}
© www.soinside.com 2019 - 2024. All rights reserved.