gpt4 book ai didi

node.js - 无法使用 TriggerAction 与 Microsoft Bot 框架 (node.js) 中的 LUIS 意图匹配

转载 作者:搜寻专家 更新时间:2023-11-01 00:28:12 25 4
gpt4 key购买 nike

我面临一个问题,即在提示选择内时无法使用triggerAction 与luis 意图匹配。对于我当前的代码,如果用户键入的单词与我硬编码的确切语句(例如“Card1”)匹配,triggerAction 将开始对话框。

当用户到达card2对话框时,它将显示消息,然后是一个包含提示问题和选择的对话框(Card2Link)。

所需:如果用户决定他/她想要键入一个或多个随机单词,该单词应尝试与 luis 意图匹配并触发意图对话框。如果随机单词不符合任何 luis 意图或不符合任何 luis 意图,则会触发“请再次选择您的选择”。

实际:当用户输入随机单词时,它不会通过 luis 意图进行搜索,并立即提供错误消息“请选择您的选择。1. Card3”。

请就这个问题提出建议。我已经被这个问题困扰了很长一段时间。

var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});

var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});

server.post('/api/messages', connector.listen());

var tableName = 'dataBT';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);


bot.beginDialogAction('Card1', '/Card1')

// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';

const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v1/application?id=' + luisAppId + '&subscription-key=' + luisAPIKey;

// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })

.matches('Card1', (session) => {
session.beginDialog('/Card1')
})

// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector);
bot.set('storage', tableStorage);

bot.dialog('/', intents);

bot.dialog('/cards', [
function (session) {

session.send('Test1');
var msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.textFormat(builder.TextFormat.xml)
.attachments([
new builder.HeroCard(session)
.title('Test1')
.images([
builder.CardImage.create(session, 'imgURL')
])
.buttons([builder.CardAction.dialogAction(session, 'Card1', null, 'Here')
])
]);
msg.addAttachment (
new builder.HeroCard(session)
.title("Test2")
.images([
builder.CardImage.create(session, "imgUrl")
])
.buttons([
builder.CardAction.dialogAction(session, "Card2", null, "Here")
])
);

session.endDialog(msg)
}
]).triggerAction({ matches: /^hi/i });

//Adding of new card
bot.dialog('/Card1', [
function (session) {
var msg1 = new builder.Message(session).sourceEvent({
//specify the channel
facebook: {
text:"Card1"
}
});

session.endDialog(msg1)
session.beginDialog('/card1link');
}
]).triggerAction({ matches: /^Card1/i });

bot.dialog('/card1link', [
function (session, args, next) {
builder.Prompts.choice(session, '1. Card2\n2. Card3\n', ['1', '2'], {
retryPrompt: "Please pick your choice.\n1. Card2\n2. Card3\n",
maxRetries: 1
});
},
function (session, args, next) {
if (args.response) {
var choice = args.response.entity;
switch (choice) {
case '1':
session.replaceDialog('Card2');
break;
case '2':
session.replaceDialog('Card3');
break;
}
}
else{
session.send("Sorry");
}
}
]);

bot.dialog('/Card2', [
function (session) {
var msg1 = new builder.Message(session).sourceEvent({
//specify the channel
facebook: {
text:"Card2"
}
});

session.endDialog(msg1)
session.beginDialog('/card2link');
}
]).triggerAction({ matches: /^Card2/i });

bot.dialog('/card2link', [
function (session, args, next) {
builder.Prompts.choice(session, '1. Card3\n', ['1'], {
retryPrompt: "Please pick your choice.\n1. Card3\n",
maxRetries: 1
});
},
function (session, args, next) {
if (args.response) {
var choice = args.response.entity;
switch (choice) {
case '1':
session.replaceDialog('Card3');
break;
}
}
else{
session.send("Sorry");
}
}
]);

最佳答案

您可以为此使用同义词。

builder.Prompts.choice(
session,
"Selection one option",
[
{
value: "1",
synonyms: ["Card1", "Card 1"]
},
{
value: "2",
synonyms: ["Card2", "Card 2"]
}
],
{
listStyle: builder.ListStyle.button,
retryPrompt: 'Selection one option.'
}
)

关于node.js - 无法使用 TriggerAction 与 Microsoft Bot 框架 (node.js) 中的 LUIS 意图匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com