javascript - 使用节点库的dialogflow v2的detectIntent()api延迟太高
问题描述
我正在尝试使用节点库调用 dialogflow 的 v2 api 的 detectIntent()。但是,我得到了平均 1.5 秒的响应延迟,与太快的 v1 api 相比,这太高了。这影响了聊天机器人的用户体验。库:- https://github.com/dialogflow/dialogflow-nodejs-client-v2
用于测试node库的detectIntent() api的代码片段,取自库的入门示例,并记录api响应时间。
// You can find your project ID in your Dialogflow agent settings
const projectId = '<project-id-here>';
const sessionId = 'fa2d5904-a751-40e0-a878-d622fa8d65d9';
const query = 'hi';
const languageCode = 'en-US';
const credentials = {
client_email: '<client-email-here>',
private_key:
'<private-key-here>',
};
// Instantiate a DialogFlow client.
const dialogflow = require('dialogflow');
const sessionClient = new dialogflow.SessionsClient({
projectId,
credentials,
});
// Define session path
const sessionPath = sessionClient.sessionPath(projectId, sessionId);
// The text query request.
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode,
},
},
};
const st = new Date();
console.log('Start Time : ', st.toISOString());
// Send request and log result
sessionClient
.detectIntent(request)
.then(responses => {
const et = new Date();
console.log('End Time : ', et.toISOString());
console.log('Duration : ', (et - st) / 1000);
console.log('Detected intent');
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
})
.catch(err => {
console.error('ERROR:', err);
});
样本输出是:-
Start Time : 2018-05-16T12:30:15.012Z
End Time : 2018-05-16T12:30:17.221Z
Duration : 2.209
Detected intent
Query: hi
Response:
Intent: intent_general_greetings
在输出中,持续时间以秒为单位。所以,我们在1-2 秒左右得到 api 响应。
有人可以帮助理解这个问题,为什么我们的延迟太高了。我有很好的互联网。我还在 aws ec2 上测试了上面的代码片段。尽管如此,在通话中还是会有这么多的延迟。
这是 v2 api 的对话流的性能吗?
解决方案
推荐阅读
- tensorflow - 用检查点替换 TensorFlow Saver
- vb.net - 包含 IP 的字符串未正确检测 IP 的前三个八位字节
- datatable - Bootstrap 4选项卡中的数据表响应
- matlab - 如何在 linux 中找到应用程序或文件的完整路径?
- regex - 使用 python3.x 中的正则表达式从文本中删除某些部分
- batch-file - 遍历字符串中的标记
- macos - Mac OS:如何在不复制进程状态的情况下分叉?
- testing - 失败时重新启动夹具
- servicestack - 自托管安全问题?
- sql - 如何在 hive 中实现无分组的计数(不同)