I am not able to get QnA Maker prompt buttons working properly. I am making standard QnA Maker REST calls like so:
if (qnAcontext == null) {
qnAcontext = {
PreviousQnaId: 0,
PreviousUserQuery: null
}
}
console.log(qnAcontext);
const qnaResult = await request({
url: url,
method: 'POST',
headers: headers,
json: {
question: query,
top: 3,
context: qnAcontext
}
});
The bot is correctly getting qnAcontext and including it in the POST request. And I can see that the values are slightly different. E.g. if I type in a prompt without context, it comes back with 32.2% confidence, and if I add the context it is higher but only 38.64%. This is well below the required score to display the answer to a user.
If I do this in the QnA Maker test panel, the followup comes back at 100%. Based on the comments in this help article, it seems that this is accomplished by passing the qnaId of the prompt in the service. However, how can I know this ID if the user hasn't selected it yet? The prompts are generated into a Hero Card, and I do have qnaId at the time I generate the card, but I don't know how that could be of use. Here is how I generate the prompt buttons:
var buttons = [];
prompts.forEach(element => {
buttons.push({
value: element.displayText,
type: ActionTypes.ImBack,
title: element.displayText
});
});
var heroCard = CardFactory.heroCard(
cardTitle,
cardText,
[],
CardFactory.actions(buttons));
I suppose I could make a separate call with the previous question and find the qnaId for the submitted query but that seems like unnecessary overhead. Surely it should be possible to get the correct result from QnA Maker with just the text and the previous question?
EDIT: I did get this working with the following bit of code, but the latency is definitely noticeable. I have to imagine there is a better way to accomplish this...
if (qnAcontext == null) {
var qnaResult = await request({
url: url,
method: 'POST',
headers: headers,
json: {
question: query,
top: 3,
context: qnAcontext
}
});
} else {
var firstResult = await request({
url: url,
method: 'POST',
headers: headers,
json: {
question: qnAcontext.PreviousUserQuery
}
});
var prompt = firstResult.answers[0].context.prompts.find(e => { return e.displayText == query });
var qnaResult = await request({
url: url,
method: 'POST',
headers: headers,
json: {
qnaId: prompt.qnaId
}
});
}