默认情况下,Dialogflow每一个输入只能匹配一个意图:
例如
User asks: "How are you?"
Dialogflow Agent responds: "I am feeling good!"
(Matched intent: intents.howareyou)
但是,一旦用户在一个输入中问了两个问题,代理就无法匹配多个意图。只有一个意图与较小的置信区间匹配)
例如
User asks: "How are you? Do we want to go shopping?"
Dialogflow Agent responds: "Yes, lets go shopping!"
(Matched intent: intents.shopping)
现在有两个选项可让代理在一次输入中回答两个问题:
根据互联网上的某些博客(例如https://docs.meya.ai/docs/handle-multiple-intents-in),第二个选择就是我所做的。
默认后备意图设置为使用实现Webhook,并执行一小部分代码:
function parseMultipleIntents (agent) {
const query = agent.query;
var pattern= /(.+?[!.?]+)/gm;
var match = pattern.exec(query);
while (match !== null) {
console.log(match[0]);
handleQuery(match[0]); //<----
match = pattern.exec(query);
}
}
handleQuery
方法是实际方法,用于处理拆分查询:
function handleQuery(query){
console.log(query);
// The path to identify the agent that owns the created intent.
const sessionPath = sessionClient.sessionPath("PROJECT_ID", "FIXED_SESSION_ID");
const request = {
session: sessionPath,
queryInput: {
text: {
text: query,
languageCode: 'de',
},
},
};
sessionClient
.detectIntent(request)
.then(responses => {
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);
});
}
问题:
如果我在handleQuery方法中注释除console.log(query);
以外的所有内容,则firebase控制台中的控制台输出看起来很好:
originalQuery: und?warum?
11:39:58.240 PM dialogflowFirebaseFulfillment warum?
11:39:58.238 PM dialogflowFirebaseFulfillment und?
但是,一旦我取消注释handleQuery的其余部分,并且代码如上所示,我就会收到以下停止停止的控制台消息。如果我在控制台中组合起来,则该消息会合一。似乎是某种循环:
-
-
我是否正确使用了detectIntent还是您有这种经历?还是可以发现问题? 我以为同步/异步调用存在问题,还添加了Promises,但是同样发生了...
谢谢