FormAction logics: compare tracker.get_slot to integer

Hey guys, I’m still trying to implement a form action and basically it’s working out good, but I’m having a problem with the extraction of a slot of type float.

I have the the following slot:

  semester:
    type: float
    max_value: 100.0
    min_value: 0.0

I want my form to ask the user in which semester he is in right now and the user to answer through an intent called give_number that has the entity number.

In the request_next_slot function of my FormAction, I have logic that should trigger something if the given number is greater than 12:

def request_next_slot(
    self,
    dispatcher: "CollectingDispatcher",
    tracker: "Tracker",
    domain: Dict[Text, Any],
) -> Optional[List[EventType]]:

    for slot in self.required_slots(tracker):
        if self._should_request_slot(tracker, slot):
    [....]                
             if tracker.get_slot('semester') > 12:
                  dispatcher.utter_message(template="utter_deny_semester")
                  dispatcher.utter_message(template="utter_can_i_help")
                  return self.deactivate()

Unfortunetly whenever my bot comes to actually starting the form, my action server throws this error:

  File "/home/sugarshock/bildungsbot-ai/actions.py", line 95, in request_next_slot
        if tracker.get_slot('semester') > 12:
TypeError: '>' not supported between instances of 'NoneType' and 'int'

Now my question is: what is the right way to make a comaprisson with my float slot value in form logics?

Hi @sugarshock,

Its because the tracker.get_slot('semester') is None and is comparing with value > 12.

.

In python 2 comparing with None will work. If you are using python 3 then you should use a try and except and see what’s the issue or write if and elif and see if the tracker.get_slot('semester') is getting filled or not

if tracker.get_slot('semester') is None:

          print("semester", tracker.get_slot('semester'))

elif tracker.get_slot('semester') > 12:

                  dispatcher.utter_message(template="utter_deny_semester")
                  dispatcher.utter_message(template="utter_can_i_help")
                  return self.deactivate()