在Dialogflow履行中,有没有一种方法可以从多个潜在响应列表中随机返回一个响应? [英] In Dialogflow fulfilment is there a way for one response to be randomly returned from a list of multiple potential responses?

查看:83
本文介绍了在Dialogflow履行中,有没有一种方法可以从多个潜在响应列表中随机返回一个响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建意图时,意图选项卡中有一个响应部分,您可以添加多个响应,然后会随机选择一个响应来响应用户。

In the Intent tab when creating an intent there is a "Responses" section and you can add multiple responses and one will be picked at random to respond to the user.

在执行调用中使用内联编辑器:

Using the inline editor in fulfilment calling:

agent.add("send a response back"); 

将命令发送回用户,但我想知道是否可以进行设置,就像在意图屏幕中,将被发送回的响应将从多个响应列表中选择:

Sends a command back to the user but I was wondering if I can set this up so that just like in the Intent screen the response to be sent back will be one picked from a list of multiple responses:

例如。

agent.add("response1");
agent.add("response2");
agent.adD("response3");

其中之一将被随机发回。

and one of these will randomly be sent back.

谢谢

推荐答案

尽管不同的响应被认为是VUI设计的最佳实践,但没有直接的方法可以做到这一点。

Although varying responses is considered best practice for VUI design, there is no direct way to do this.

但是,解决此问题的最佳方法是将可能的答复放入一个数组中,然后随机选择其中一个。像这样:

However, the best way to approach this problem is to have the possible replies in an array, and then picking one of them randomly. Something like this:

var possibleResponse = [
  'Response 1',
  'Response 2',
  'Response 3'
];

var pick = Math.floor( Math.random() * possibleResponse.length );

var response = possibleResponse[pick];
agent.add( response );

这也更好,因为当您将Action国际化时,只需替换 possibleResponse 和本地化的字符串。

This is also better because when you go to internationalize your Action, you can just replace the possibleResponse with localized strings.

实际上,这是解决该问题的一种流行方法,即 multivocal 库使其成为其解决方案的核心。您只需在配置中为动作,目的或结果提供可能的本地化响应,它就会为您选择一个响应。而且由于所有响应都是模板,因此您可以添加任何其他所需参数或在显示它们时加上条件(例如处理单数或复数值)。因此,在多声系统中,配置的这一部分将是:

In fact, this was such a popular approach to the problem, that the multivocal library made it the core of its solution. You just provide the possible localized responses for an Action, Intent, or Outent in the configuration and it takes care of picking one for you. And since all the responses are templates, you can add whatever other parameters you want or put conditions on displaying them (such as handling singular or plural values). So in multivocal, this part of the configuration would be:

Local: {
  en: {
    Response: {
      "Intent.welcome": [
        "Response 1",
        "Response 2",
        "Response 3"
      ]
    }
  }
}

这篇关于在Dialogflow履行中,有没有一种方法可以从多个潜在响应列表中随机返回一个响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆