can i pass top 3 predicted responses to custom action?
i need highest top 3 confidence scored “responses”
can i pass top 3 predicted responses to custom action?
i need highest top 3 confidence scored “responses”
Check out the tracker
object, it’s the only thing that can help with stuff like that
Reference: Tracker
@ChrisRahme i think tracker can only return One predicted response. I need 3 predicted responses. Please help me
from typing import Any, Dict, List, Text
from rasa_sdk import Action, Tracker
from rasa_sdk.events import UserUtteranceReverted
from rasa_sdk.executor import CollectingDispatcher
class ActionDefaultFallback(Action):
def name(self) -> Text:
return "action_default_fallback"
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict[Text, Any]]:
# tell the user they are being passed to a customer service agent
# assume there's a function to call customer service
# pass the tracker so that the agent has a record of the conversation between the user
# and the bot for context
latest_message = tracker.current_state()['latest_message']
intent_ranking = latest_message.get("intent_ranking")
buttons = []
if not intent_ranking:
return None
for i in range(5):
if intent_ranking[i]['name'] == "nlu_fallback" or intent_ranking[i]['confidence']==0:
continue
else:
buttons.append({"payload":"/{0}".format(intent_ranking[i]['name']),"title":intent_ranking[i]['name']})
dispatcher.utter_message(buttons=buttons)
# pause the tracker so that the bot stops responding to user input
return []
Try this, rewrite the “action_default_fallback” action, return top 5 intent let user to choice
This is my config.yml, FallbackClassifier is necessary
language: zh
pipeline:
- name: SpacyNLP
model: "zh_core_web_lg"
- name: SpacyTokenizer
# - name: SpacyEntityExtractor
- name: SpacyFeaturizer
pooling: mean
- name: DIETClassifier
epochs: 1000
learning_rate: 0.001
- name: EntitySynonymMapper
- name: FallbackClassifier
threshold: 0.4
ambiguity_threshold: 0.1
@diorw thx.
i will try your code then tell you.
My rasa version is 3.0.2