gpt4 book ai didi

node.js - 如何在 app.js 中使用 LUIS 来识别不同文件夹中的对话框

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:11 25 4
gpt4 key购买 nike

微软 BotbuilderSDK:3.15.0语言:NodeJs

我的对话框位于不同的文件夹中。但是,我尝试在 app.js 文件夹中初始化它们,以便在意图与对话框匹配时可以使用 LUIS,但它不起作用。

注意 - 当我以类似于以下的结构调用它们时,每个对话框都会起作用:

session.beginDialog('hello:Hello')

这里是完整的源代码:

require('dotenv').config();
const restify = require('restify');

const builder = require('botbuilder');

var fs = require('fs');

var clients = require('restify-clients');

var azure = require('botbuilder-azure');

var listenPort = process.env.port || process.env.PORT || 3978;

var server = restify.createServer()

server.listen(listenPort, '::', () => {
console.log(`smooth like a baby's bottom`)
});


var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});


var bot = new builder.UniversalBot(connector, function (session) {
session.endDialog(`I'm sorry, I did not understand '${session.message.text}'.\nType 'help' to know more about me :)`)
}).set('storage', cosmosStorage);


var luisRL = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL).onEnabled(function (context, callback) {
var enabled = context.dialogStack().length === 0
callback(null, enabled)
});


var intents = new builder.IntentDialog({ recognizers: [luisRL] });
bot.recognizer(intents);


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

bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {

greetings = 'welcome to Joey's Pizza?'

message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.send(new builder.Message()
.address(message.address)
.text(greetings)
)
}
})
}
});

bot.library(require('./dialogs/reservations').createLibrary());
bot.library(require('./dialogs/order').createLibrary());
bot.library(require('./dialogs/cancellations').createLibrary());

最佳答案

这是一个完整的示例,演示了从 LUIS 意图触发的库文件中的对话框:

带有启动文件,例如:

require('dotenv').config();
const restify = require('restify');
const builder = require('botbuilder');

var listenPort = process.env.port || process.env.PORT || 3978;
var server = restify.createServer();
server.listen(listenPort, '::', () => {
console.log(`smooth like a baby's bottom`)
});

var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var inMemoryStorage = new builder.MemoryBotStorage();

var bot = new builder.UniversalBot(connector, function (session) {
session.endDialog(`I'm sorry, I did not understand '${session.message.text}'.\nType 'help' to know more about me :)`)
}).set('storage', inMemoryStorage);

var luisRL = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL).onEnabled(function (context, callback) {
var enabled = context.dialogStack().length === 0
callback(null, enabled)
});

var intents = new builder.IntentDialog({ recognizers: [luisRL] });
bot.recognizer(intents);

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

bot.on('conversationUpdate', function (message) {
if (message.membersAdded) {

greetings = `Ask to set or change your name...`;

message.membersAdded.forEach(function (identity) {
if (identity.id === message.address.bot.id) {
bot.send(new builder.Message()
.address(message.address)
.text(greetings)
)
}
})
}
});

bot.library(require('./dialogs/profile').createLibrary());

具有以下/dialogs/profile/index.js

var builder = require('botbuilder');


var lib = new builder.Library('profile');
exports.createLibrary = function () {
return lib.clone();
}

lib.dialog('changeName', [
function (session) {
debugger;
session.dialogData.updating = session.userData.hasOwnProperty('name');
var prompt = session.dialogData.updating ? "What would you like to change your name to?" : "Hi... What's your name?";
builder.Prompts.text(session, prompt);
},
function (session, results) {
session.userData.name = results.response;
session.endDialog("Got it %s...", session.userData.name);
}
]).triggerAction({ matches: 'ChangeNameIntent' });

使用以下 LUIS 模型:

{
"luis_schema_version": "3.1.0",
"versionId": "0.1",
"name": "ChangeNameLuisModel",
"desc": "",
"culture": "en-us",
"intents": [
{
"name": "ChangeNameIntent"
},
{
"name": "getage"
},
{
"name": "None"
}
],
"entities": [
{
"name": "speed",
"roles": []
}
],
"composites": [],
"closedLists": [],
"patternAnyEntities": [],
"regex_entities": [],
"prebuiltEntities": [
{
"name": "number",
"roles": []
}
],
"model_features": [],
"regex_features": [],
"patterns": [],
"utterances": [
{
"text": "allow me to change my name",
"intent": "ChangeNameIntent",
"entities": []
},
{
"text": "change my name",
"intent": "ChangeNameIntent",
"entities": []
},
{
"text": "change name",
"intent": "ChangeNameIntent",
"entities": []
},
{
"text": "i am 10 years old",
"intent": "getage",
"entities": []
},
{
"text": "i am 12 years old",
"intent": "getage",
"entities": []
},
{
"text": "i want to change my name",
"intent": "ChangeNameIntent",
"entities": []
},
{
"text": "let me alter my name",
"intent": "ChangeNameIntent",
"entities": []
},
{
"text": "name change",
"intent": "ChangeNameIntent",
"entities": []
},
{
"text": "please change my name",
"intent": "ChangeNameIntent",
"entities": []
}
],
"settings": []
}

关于node.js - 如何在 app.js 中使用 LUIS 来识别不同文件夹中的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53202273/

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