以下代码片段来自 watson 音调分析器文档。问题:当我粘贴代码并运行代码时,它运行得非常好。但是,当我将它粘贴到另一个云函数中时,它表明找不到 ibm-watson/auth 模块。不知道为什么它的行为不同?
通常我保存在函数 main (params){} 下。但是,另一个云函数是异步函数,它具有 (require-promise) 的代码。不知道出了什么问题或问题是什么?
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/sdk');
const toneAnalyzer = new ToneAnalyzerV3({
version: '2017-09-21',
authenticator: new IamAuthenticator({
apikey: 'apikey',
}),
serviceUrl: 'url',
});
const text = 'Team, I know that times are tough! Product '
+ 'sales have been disappointing for the past three '
+ 'quarters. We have a competitive product, but we '
+ 'need to do a better job of selling it!';
const toneParams = {
toneInput: { 'text': text },
contentType: 'application/json',
};
toneAnalyzer.tone(toneParams)
.then(toneAnalysis => {
console.log(JSON.stringify(toneAnalysis, null, 2));
})
.catch(err => {
console.log('error:', err);
});
}