首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >海底框架v4:瀑布& LUIS.ai

海底框架v4:瀑布& LUIS.ai
EN

Stack Overflow用户
提问于 2019-09-11 10:35:56
回答 3查看 282关注 0票数 0

我尝试实现一个简单的预订聊天机器人来测试LUIS.ai和Node.js Botframework。有些事情我不太清楚:当用户语句与实现Waterfall对话框的intente匹配时,该对话框的每个步骤都不会返回到NLU提取实体吗?

例如,我有一个BookingDialog,实现了一个Waterfall。用户说“我想预订旅行”,我的机器人的第一个问题是“好的,你想去哪里?”在这一步,我的机器人在等待一个城市。但是,如果用户回复"lkjqbdfgoiqsjflqdis",机器人将进入下一步,并说“您有多少人参加这次旅行?”

在这种情况下,我想实现一个解决方案,机器人回答说:“哦,我不知道……你想去哪里?”NLU在一个城市里不匹配吗。

可以用Node.js Botframework实现这种对话吗?

EN

回答 3

Stack Overflow用户

发布于 2019-09-12 05:25:06

是的,您可以使用Node.js Botframework实现这一点。这是一个由nodejs编码的官方瀑布样本。此演示主要用于收集与您的需求类似的用户的信息。

对于您需要验证用户城市输入的验证的另一个要求,您应该实现自己的判断逻辑。据我所知,https://www.weather-forecast.com/提供了一个API:

代码语言:javascript
复制
GET https://www.weather-forecast.com/locations/ac_location_name?query=<the city user inputed>

如果城市名称无效,您将得到一个空响应,如:

代码语言:javascript
复制
https://www.weather-forecast.com/locations/ac_location_name?query=aaaa

一个有效的:

代码语言:javascript
复制
https://www.weather-forecast.com/locations/ac_location_name?query=new%20york

当然,您也可以使用Azure地图查询城市。总之,这完全是基于你自己的要求。

对于Q2,你可以根据你的需求在你的路易斯应用程序中添加“模板话语”,这样你就可以从用户输入的句子中得到特定的i,e城市名称。关于细节,这位医生解释得很好。

希望能帮上忙。

票数 0
EN

Stack Overflow用户

发布于 2019-09-12 09:19:49

(谢谢斯坦利的答覆:)

我理解您的解决方案,如果用户只回答城市的话,这个解决方案是可行的:

  • 机器人:“你想去哪里?”
  • 用户:"Paris“

但是,如果用户回答“我想去巴黎”,API就不会理解这个城市。这就是为什么我想回到路易斯身边。

票数 0
EN

Stack Overflow用户

发布于 2019-09-12 15:27:45

您可以通过在瀑布对话步骤中的任何话语中调用LUIS来做到这一点:

代码语言:javascript
复制
/**
     * Second step in the waterfall.  This will use LUIS to attempt to extract the origin, destination and travel dates.
     * Then, it hands off to the bookingDialog child dialog to collect any remaining details.
     */
    async actStep(stepContext) {

        // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt)
        const luisResult = await this.luisRecognizer.executeLuisQuery(stepContext.context);
        switch (LuisRecognizer.topIntent(luisResult)) {
        case 'BookFlight':
            // Extract the values for the composite entities from the LUIS result.
            const fromEntities = this.luisRecognizer.getFromEntities(luisResult);
            const toEntities = this.luisRecognizer.getToEntities(luisResult);

            // Show a warning for Origin and Destination if we can't resolve them.
            await this.showWarningForUnsupportedCities(stepContext.context, fromEntities, toEntities);

            // Initialize BookingDetails with any entities we may have found in the response.
            bookingDetails.destination = toEntities.airport;
            bookingDetails.origin = fromEntities.airport;
            bookingDetails.travelDate = this.luisRecognizer.getTravelDate(luisResult);
            console.log('LUIS extracted these booking details:', JSON.stringify(bookingDetails));

            // Run the BookingDialog passing in whatever details we have from the LUIS call, it will fill out the remainder.
            return await stepContext.beginDialog('bookingDialog', bookingDetails);

        case 'GetWeather':
            // We haven't implemented the GetWeatherDialog so we just display a TODO message.
            const getWeatherMessageText = 'TODO: get weather flow here';
            await stepContext.context.sendActivity(getWeatherMessageText, getWeatherMessageText, InputHints.IgnoringInput);
            break;

        default:
            // Catch all for unhandled intents
            const didntUnderstandMessageText = `Sorry, I didn't get that. Please try asking in a different way (intent was ${ LuisRecognizer.topIntent(luisResult) })`;
            await stepContext.context.sendActivity(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
        }

        return await stepContext.next();
    }

这是“CoreBot”中瀑布对话框的第二步,CoreBot是Bot框架示例回购上的LUIS示例。

我从你的问题中看出你可能已经在看那个样本了。bookingDialog.js在CoreBot中的问题是,当您的LUIS没有配置时,就会专门调用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57887264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档