I am trying to use TwoStageFallbackPolicy. But after denying to action ‘action_default_ask_affirmation’ not calling next action for rephrasing my input.
Is there any idea how to I achieve this.
I am trying to use TwoStageFallbackPolicy. But after denying to action ‘action_default_ask_affirmation’ not calling next action for rephrasing my input.
Is there any idea how to I achieve this.
could you please share your code here so that I can review it
# This files contains your custom actions which can be used to run
# custom Python code.
#
# See this guide on how to implement these action:
# https://rasa.com/docs/rasa/core/actions/#custom-actions/
# This is a simple example for a custom action which utters "Hello World!"
from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
import csv
#
#
# class ActionHelloWorld(Action):
#
# def name(self) -> Text:
# return "action_hello_world"
#
# def run(self, dispatcher: CollectingDispatcher,
# tracker: Tracker,
# domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#
# dispatcher.utter_message("Hello World!")
#
# return []
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 from a csv and store it in a dictionary
with open('intent_mapping.csv', 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):
# get the most likely intent
last_intent_name = tracker.latest_message['intent']['name']
print('last_intent_name ',last_intent_name)
# get the prompt for the intent
intent_prompt = self.intent_mappings[last_intent_name]
print('intent_prompt ',intent_prompt)
# 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(last_intent_name)},
{'title': 'No',
'payload': '/out_of_scope'}]
dispatcher.utter_button_message(message, buttons=buttons)
return []
>
actions.py file
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en
pipeline: supervised_embeddings
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
- name: MemoizationPolicy
- name: KerasPolicy
- name: MappingPolicy
- name: TwoStageFallbackPolicy
nlu_threshold: 0.3
ambiguity_threshold: 0.1
core_threshold: 0.3
fallback_core_action_name: "action_default_fallback"
fallback_nlu_action_name: "action_default_fallback"
deny_suggestion_intent_name: "out_of_scope"
config.yml file
Same issue here!
Did you define the “out_of_scope” intent in the intent section of domain.yml ?
yes, i do - sorry for late reply
add default fallback to domain.yml
action