0

我正在尝试将 IBM Watson Dialog 服务与 Node.js 一起使用。

我在这里关注 Node.js 的 API 参考https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/dialog/api/v1/?node#

据此,创建对话框的方法是这样的:

var fs     = require('fs');
var watson = require('watson-developer-cloud');
var dialog_service = watson.dialog({
  username: '{username}',
  password: '{password}',
  version: 'v1'
});

var params = {
  name: 'my-dialog',
  file: fs.createFileStream('template.xml')
};

dialog_service.createDialog(params, function(err, dialog) {
  if (err)
    console.log(err)
  else
    console.log(dialog);
});

但是函数 fs.createFileStream 不存在,所以我使用 fs.createWriteStream 和相同的代码。

但是当我尝试运行时,我收到以下错误

/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:35
    source.pause();

TypeError: source.pause is not a function
    at Function.DelayedStream.create (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:35:12)
    at FormData.CombinedStream.append (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/lib/combined_stream.js:43:37)
    at FormData.append (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/node_modules/form-data/lib/form_data.js:46:3)
    at appendFormValue (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/request.js:339:21)
    at Request.init (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/request.js:350:11)
    at new Request (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/request.js:140:8)
    at request (/home/ubuntu/workspace/node_modules/watson-developer-cloud/node_modules/request/index.js:55:10)
    at createRequest (/home/ubuntu/workspace/node_modules/watson-developer-cloud/lib/requestwrapper.js:131:10)
    at Dialog.createDialog (/home/ubuntu/workspace/node_modules/watson-developer-cloud/services/dialog/v1.js:192:10)
    at Object.<anonymous> (/home/ubuntu/workspace/dialog.js:15:16)

任何想法为什么这个暂停功能不起作用?该错误显示在 watson-developer-cloud 包中的一个模块上,因此它不是我的代码的一部分。

4

1 回答 1

5

功能是createReadStream()

参数应该是:

var params = {
  name: 'my-dialog',
  file: fs.createReadStream('template.xml')
};

文档:fs。createReadStream()

于 2016-01-22T19:58:41.677 回答