应用情形:在现有的Form填槽的过程中检测到新的意图,采用暴力覆盖原有Form的slots,并开始新意图的Form
假设现有意图包括:ask_route, ask_price, ask_train_time。
在rules.yml中添加处理新意图的规则
version: "3.0"
rules:
- rule: repeat ask route during route form
condition:
- active_loop: route_form
steps:
- intent: ask_route
- action: utter_test_success
- action: action_slot_reset # for test
- action: action_restarted # for test
- rule: repeat ask price during route form
condition:
- active_loop: route_form
steps:
- intent: ask_price
- action: utter_test_success
- action: action_slot_reset # for test
- action: action_restarted # for test
- rule: repeat ask train time during route form
condition:
- active_loop: route_form
steps:
- intent: ask_train_time
- action: utter_test_success
- action: action_slot_reset # for test
- action: action_restarted # for test
在actions.py中添加对应reset和restart的action
# for test
class ActionRestarted(Action):
def name(self):
return 'action_restarted'
def run(self, dispatcher, tracker, domain):
return[Restarted()]
class ActionSlotReset(Action):
def name(self):
return 'action_slot_reset'
def run(self, dispatcher, tracker, domain):
#获得nlu数据(意图和词槽数据)
content = tracker.latest_message
intent = content['intent']['name']
dispatcher.utter_message("{} ".format(intent))
if intent == 'ask_route':
return [AllSlotsReset(), Form("route_form")]
elif intent == 'ask_price':
return [AllSlotsReset(), Form("price_form")]
elif intent == 'ask_train_time':
return [AllSlotsReset(), Form("train_time_form")]
else:
return [AllSlotsReset()]
网友评论