简体   繁体   English

我如何在 Rasa 的自定义操作中使用 action_listen

[英]How can i use action_listen inside a custom action in Rasa

I want to listen to user inside custom action and then continue that custom action.我想在自定义操作听取用户的意见,然后继续该自定义操作。 Basically what i am looking for is.基本上我要找的是。

I have a loop in custom action from 0 to 5. for each value i want to take some input from user and continue that loop.我有一个从 0 到 5 的自定义操作循环。对于每个值,我想从用户那里获取一些输入并继续该循环。

def Action():
   for 0 to 5:
      input = action_listen
      // do something with input

You should use a form for this.您应该为此使用表格 A form loops over a set of slots that you define until all are filled.表单循环遍历您定义的一组槽,直到所有槽都被填满。

Looping with action_listen in a regular action won't work because an action has only one run() method and the events are only added to the tracker once the run() method has returned, after which the action is completed (and you can't get back into it).在常规动作中使用action_listen循环将不起作用,因为动作只有一个run()方法,并且只有在run()方法返回后事件才会添加到跟踪器,之后动作完成(你可以'不要回到它)。

https://rasa.com/docs/rasa/core/forms/ https://rasa.com/docs/rasa/core/forms/

Thanks for your response, but some tricks also works for me to do the same in custom action.感谢您的回复,但一些技巧也适用于我在自定义操作中执行相同的操作。

I returned the Form as FollowUpAction at each iteration and reduce the loop variable by one.我在每次迭代时将Form作为FollowUpAction返回,并将循环变量减一。

Now the Form will ask the user to get required slot (Do the needful with with information) and again Set the slot to None with SlotSet.现在表单将要求用户获取所需的插槽(使用信息执行必要的操作)并再次使用 SlotSet 将插槽设置为 None。 Now return the Action as FollowUpAction in form.现在以FollowUpAction形式返回Action

In this way for each iteration Bot will take response from user.这样,对于每次迭代,Bot 都会从用户那里获取响应。

global i = 0
class Action():
   def run():
      for i to 5:
         return [FollowUpAction('ActionForm')]

class ActionForm():
   def requiredslot():
         return ['take_value']

   def submit():
         //Do needful with input
         return [SlotSet("take_value", None), FollowUpAction("my_action")]

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

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