使用节点库的dialogflow v2的DetectIntent() api延迟太高

Aks*_*ngh 5 javascript node.js dialogflow-es

我正在尝试使用节点库调用dialogflow v2 api的DetectIntent()。但是,我的响应延迟平均为 1.5 秒,与速度太快的 v1 api 相比,这太高了。这正在影响聊天机器人的用户体验。库:- https://github.com/dialogflow/dialogflow-nodejs-client-v2

用于测试 Node 库的detectorIntent() 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);
  });
Run Code Online (Sandbox Code Playgroud)

示例输出为:-

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
Run Code Online (Sandbox Code Playgroud)

在输出中,持续时间以秒为单位。因此,我们会在1-2 秒左右收到 api 响应。

有人可以帮助理解这个问题,为什么我们的延迟太高。我有良好的网络。我还在 aws ec2 上测试了上面的代码片段。尽管如此,通话延迟仍然如此之多。

这是v2 api的dialogflow的性能吗?