Possible to assign variable if intent is found?

Hello everyone,

This might be basic but I was wondering if it was possible to set a variable when an intent is found without extracting an entity and then using that variable later on.

Kind of hard to explain so let me use an example:

Say you have two intents. One is for if someone is talking about apples and the other oranges. Now say you don’t want to extract an entity (apple or orange in this case) because it is unreliable and instead what you want to do is create a variable if an entity is detected. For example lets say the person is talking about apples and it detects that intent = apples you would set a var (var = “apples”).

I am asking because lets say in your domain file you have utter_question and it follows a template like utter_question:

  • text: Oh I see you’re talking about ______ would you say you like them?

    buttons:

    • title: Yes payload: /affirm
    • title: No payload: /deny

In this case if you could replace the _____ with either apple or oranges you wouldn’t have to create diferent utter statements. Obviously with only 2 it isn’t a big deal but imagine if we wanted to ask the same question about 100 different things but the string was the exact same as opposed to the specific ______ part.

Thanks

Yes, what you can do is set slot value by adding a custom action. Let’s say you have a slot named “intents” that carries the value of an intent the user is talking about.

Inside your domain file add it: slots: intents: type: text

Define a custom action that sets the slot “intent” value whenever the intent is triggered.

class ActionSetIntents(Action): def name(self): return “action_set_intents”

def run(self, dispatcher, tracker, domain):

    intent_current = tracker.latest_message['intent'].get('name')
    return [SlotSet("intents", intent_current)]

Your utter_template would be utter_example: text: Oh I see you’re talking about {intents}. Would you say you like them?

Stories go like:

  • apples
  • action_set_intents
  • utter_example
  • banana
  • action_set_intents
  • utter_example
1 Like