对话机器人 Rasa(二十四):两例多返回额外消息的 bug 定位

更新日期: 2023-09-17 阅读次数: 653 字数: 533 分类: AI

今天又遇到一例 Rasa 对话多返回额外消息的 Bug,结合之前遇到的另外一例,都非常具有代表性, 有必要总结一下。避免之后再出现此类问题,浪费时间去调试。

具体细节就不贴日志了,直接上结论。

现象

表现的现象都是一样的,就是本来用过对一个消息返回一条回复,例如:

response1

但是实际返回是

[response1, response2]

多返回了一条。而且这条还是固定的,但是找不到关联性在哪里。

Bug 1:未加 slot_was_set,导致两个 story 没有区分度

custom action 中对查询到数据和未查询到做了不同的回复。 但是由于没有区分,导致在返回查询结果时,总是多了一条不相干的回复。

解决方法使用 slot_was_set 区分两种场景:

if condition:
	return [
		SlotSet("find_items", true),
		FollowupAction("action_deactivate_loop"),
	]
else:
	return [
		SlotSet("find_items", None),
		FollowupAction("utter_not_found"),
	]

对应的 story:

- story: success
  steps:
  - intent: query_data
  - action: action_find_items
  - slot_was_set:
    - find_items: true

- story: fail
  steps:
  - intent: query_data
  - action: action_find_items
  - slot_was_set:
    - find_items: false
  - action: utter_not_found

定义 slot

find_items:
  type: bool
  influence_conversation: true
  mappings:
  - type: custom

同时这个案例也提醒了我:

slot,action 凡是在 custom action 中 return 的,在 story 中都需要准确写出,除非是 slot 为 None 的情况。

Bug 2: utter_ask_xxx 与 Form Slot 规则冲突

这个 Bug 耗费了半天时间去排查,整个人都不好了。

出现的场景是,在 form 中为 slot 赋值时,总是会多一条回复。

后来逐一排查发现:

Once the form action gets called for the first time, the form gets activated and will prompt the user for the next required slot value. It does this by looking for a response called utter_ask_formname_slotname or utter_ask_slotname if the former isn't found. Make sure to define these responses in your domain file for each required slot.

定义的一个 utter_ask_xxx 的回复与 form slot 提示规则名碰巧一致。

于是触发了这条 utter,每次进入 form loop 时,都会准时出现。。。

所以,一定要慎用 utter_ask 为前缀的回复规则。

查看合集

📖 对话机器人 Rasa 中文系列教程

tags: rasa

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式