简体   繁体   English

如何在 rasa 中发出用户输入错误消息?

[英]How to give out user input error messages in rasa?

how to give out error messages if a user input doesn't match any intents.如果用户输入与任何意图不匹配,如何发出错误消息。 Example: I am making a restaurant finding rasa bot, so I was thinking of making the rasa bot ask location of where the user is looking for a restaurant, So if there are no restaurants in location entered by the user how to return “sorry there are no restaurants in this location” message.示例:我正在制作一家餐厅寻找 rasa 机器人,所以我正在考虑让 rasa 机器人询问用户在哪里寻找餐厅的位置,所以如果用户输入的位置没有餐厅如何返回“对不起此位置没有餐厅”消息。

You should be able to create this behaviour using a rule and a slot.您应该能够使用规则和插槽创建此行为。 For example:例如:

- rule: nothing found
  condition:
  - slot_was_set:
    - restaurant_found: false
  steps:
  - action: utter_no_restaurants_found

You'll need to create a boolean slot for restaurant_found and set this to false or true in a custom action.您需要为restaurant_found创建一个 boolean 插槽,并在自定义操作中将其设置为 false 或 true。

slots:
  restaurant_found:
    type: bool

The custom action would look something like this (you need to add the "successful" condition, and whatever your code does to search for a restaurant.)自定义操作看起来像这样(您需要添加“成功”条件,以及您的代码为搜索餐厅所做的任何事情。)

class RestaurantSearchAction(Action):

    def name(self) -> Text:
        return "restaurant_search"

    async def run(
        self, dispatcher, tracker: Tracker, domain: Dict[Text, Any],
    ) -> List[Dict[Text, Any]]:
        # search for restaurant with your
        # custom code here. You can get entities
        # from the tracker like so: tracker.get_latest_entity_values
        if <successful>:
            return [SlotSet(restaurant_found, True)]
        else:
            return [SlotSet(restaurant_found, False)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM