如何修复Rasa中选择按钮触发的UserWarning参数解析错误?
修复Rasa聊天机器人choose_topic意图的UserWarning错误
问题场景
聊天机器人展示“astreinte”和“support”选项按钮,用户点击任一按钮后触发如下UserWarning:
"UserWarning: Failed to parse arguments in line '/choose_topic{"topic": "astreinte"}'. Expected entities from [] but found {'topic'}. Continuing without unknown entity types."
相关配置文件:
nlu.yml(注:原文件名写为nly.yml,应为笔误,需修正为nlu.yml)
- intent: choose_topic examples: | - '/choose_topic{"topic": "astreinte"}' - '/choose_topic{"topic": "support"}'
domain.yml
utter_greet_with_options: - text: "Bonjour, voulez-vous avoir des informations sur l'astreinte ou le support ?" buttons: - title: "astreinte" payload: '/choose_topic{"topic": "astreinte"}' - title: "support" payload: '/choose_topic{"topic": "support"}'
修复步骤
错误核心是未在配置中声明topic实体,Rasa无法识别payload中携带的topic参数,按以下步骤修复:
修正NLU文件名
将原nly.yml重命名为nlu.yml,这是Rasa默认的NLU训练数据文件名,避免加载异常。在domain.yml中声明
topic实体
在domain.yml中添加entities字段,明确声明topic实体:entities: - topic utter_greet_with_options: - text: "Bonjour, voulez-vous avoir des informations sur l'astreinte ou le support ?" buttons: - title: "astreinte" payload: '/choose_topic{"topic": "astreinte"}' - title: "support" payload: '/choose_topic{"topic": "support"}'优化nlu.yml的意图示例(可选)
建议将NLU示例改为自然语言标注实体的形式,更符合Rasa训练逻辑,提升模型泛化能力:- intent: choose_topic examples: | - Je veux des informations sur l'[astreinte](topic) - Je préfère le [support](topic) - Informations sur l'astreinte - Aide pour le support若需保留原payload示例,确保格式正确即可。
重新训练模型
执行训练命令让配置生效:rasa train
内容的提问来源于stack exchange,提问作者enji cakeup
相关产品推荐
相关产品推荐

