我正在尝试将IBM Watson Dialog服务与Node.js一起使用。
我正在遵循 Node 的 API 参考.js这里 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 包中的一个模块上,因此它不是我代码的一部分。
函数createReadStream()
参数应为:
var params = {
name: 'my-dialog',
file: fs.createReadStream('template.xml')
};
文档:fs。createReadStream
()