用户回复超出范围的消息后的表单填充槽 [已解决]

问题描述

我有以下故事:

story: survey continue                                                      
  steps:                                                                   
  - intent: greet                                                          
  - action: utter_greet                                                    
  - intent: affirm                                                         
  - action: health_form                                                    
  - active_loop: health_form                                               
  - intent: out_of_scope                                                   
  - action: utter_ask_continue                                             
  - intent: affirm                                                         
  - action: health_form                                                    
  - active_loop: null                                                      
  - action: utter_slots_values 

让我们假设以下对话:

1 Me: hello
2 Bot: Hi! It's time for your daily wellness check. Tracking healthy habits is a great way to measure your progress over time. Would you like to answer a few questions about your health?
3 Me: yes please
4 Bot: Did you exercise yesterday? Don't sweat it if you didn't run a marathon - walks count!
5 Me: wait stop
6 Bot: Sorry,I don't quite understand. Do you want to continue?
7 Me: actually yes
8 Bot: What kind of exercise did you do?

如您所见,在第 7 条消息中,如果用户做出肯定意图,它会回答第 6 条消息中提出的问题以及第 4 条消息中提出的问题。

我希望对话流程是这样的:

[...]
6 Bot: Sorry,I don't quite understand. Do you want to continue?
7 Me: actually yes
8 Bot: Did you exercise yesterday? Don't sweat it if you didn't run a marathon - walks count!

这是预期的行为吗?我怎样才能达到我心目中的预期流量?

解决方

actions.py 中,向那些修改机器人内存的 extract_<slot_name> 函数添加更严格的条件,其意图与回答 utter_ask_continue 问题的意图相同。

if (not tracker.slots.get('requested_slot') == "confirm_exercise" or tracker.get_last_event_for(event_type="action",exclude=["health_form"],skip=1)['name'] == "utter_ask_continue"):
  return {}

查看此 GitHub issue获取有关解决方案的完整信息。

解决方法

尝试将您的表单设置为在 active_loop 下再次运行,而不是 null。来自 Rasa 官网的示例故事,关于如何在另一个 Intent 之后“返回”表单 here

rules:
- rule: Example of an unhappy path
  condition:
  # Condition that form is active.
  - active_loop: restaurant_form
  steps:
  # This unhappy path handles the case of an intent `chitchat`.
  - intent: chitchat
  - action: utter_chitchat
  # Return to form after handling the `chitchat` intent
  - action: restaurant_form
  - active_loop: restaurant_form

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...