在后备策略中,rasa 显示最可能意图的选项。
默认情况下,Rasa 显示回退的原始意图名称,因为我们没有提供任何映射配置。因此,如果它找到了意图make_reserverations
,它将显示
Did you mean make_reserverations?
并提供两个按钮是和否。
要显示自定义或用户友好的短语,需要实施该操作action_default_ask_affirmation
您必须在actions.py中创建一个类
class ActionDefaultAskAffirmation(Action):
"""Asks for an affirmation of the intent if NLU threshold is not met."""
def name(self):
return "action_default_ask_affirmation"
def __init__(self):
self.intent_mappings = {}
# read the mapping of 'intent and valid question' from a csv and store it in a dictionary
with open(
INTENT_DESCRIPTION_MAPPING_PATH, newline="", encoding="utf-8"
) as file:
csv_reader = csv.reader(file)
for row in csv_reader:
self.intent_mappings[row[0]] = row[1]
def run(self, dispatcher, tracker, domain):
# from the list of intents get the second higher predicted intent
# first will be nlu_fallback
predicted_intent_info = tracker.latest_message["intent_ranking"][1]
# get the most likely intent name
intent_name = predicted_intent_info["name"]
# get the prompt for the intent
intent_prompt = self.intent_mappings[intent_name]
# Create the affirmation message and add two buttons to it.
# Use '/<intent_name>' as payload to directly trigger '<intent_name>'
# when the button is clicked.
message = "Did you mean '{}'?".format(intent_prompt)
buttons = [
{"title": "Yes", "payload": "/{}".format(intent_name)},
{"title": "No", "payload": "/out_of_scope"},
]
dispatcher.utter_message(message, buttons=buttons)
return []
然后需要像这样映射csv文件
//intent_name,User_Friendly_Phrase
bot_challenge,I am bot
然后在domain.yml下创建一个条目actions