Rasa: Problem with self.validate_slots in def validate after updating rasa to version 1.7.0

Created on 12 Feb 2020  Â·  3Comments  Â·  Source: RasaHQ/rasa

Rasa version: 1.7.0

Rasa SDK version (if used & relevant): 1.7.0

Rasa X version (if used & relevant):

Python version: 3.7.6

Operating system (windows, osx, ...): Manjaro

Issue: FormAction stopped working in the new version 1.7.0 of rasa

Hello everyone!

After updating the version of rasa from 1.6.1 to version 1.7.0, a FormAction stopped working. The function of this FormAction is to ask for the phone number, which is an entity and to ask for the name of the phone’s display, which is a free text slot. This works perfectly in version 1.6.1 of rasa.

Here is my FormAction

actions.py

class SolicitarConfiguracaoPersonalizacaoRamalForm(FormAction):
    def name(self):
        return "solicitar_configuracao_personalizacao_ramal_form"

    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        return ["entidade_numeros_ramal", "nome_visor"]

    def request_next_slot(self, dispatcher, tracker, domain):
        for slot in self.required_slots(tracker):
            if self._should_request_slot(tracker, slot):
                if slot == 'nome_visor':
                    dispatcher.utter_template('utter_nome_visor', tracker)
                if slot == 'entidade_numeros_ramal':
                    dispatcher.utter_template('utter_entidade_numeros_ramal_personalizar_ramal', tracker)
                return [SlotSet(REQUESTED_SLOT, slot)]
        return None

    def validate(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]:
        slot_to_fill = tracker.get_slot(REQUESTED_SLOT)
        if slot_to_fill == 'nome_visor':
            return [SlotSet(slot_to_fill, tracker.latest_message['text'])]
        else:
            slot_values = self.extract_other_slots(dispatcher, tracker, domain)
            if slot_to_fill:
                slot_values.update(self.extract_requested_slot(dispatcher, tracker, domain))
                if not slot_values:
                    raise ActionExecutionRejection(
                        self.name(),
                        f"Failed to extract slot {slot_to_fill} with action {self.name()}",
                    )
            logger.debug(f"Validating extracted slots: {slot_values}")
            return self.validate_slots(slot_values, dispatcher, tracker, domain)

    def slot_mappings(self):
        return {
                "visor_ramal": self.from_text(),
                "entidade_numeros_ramal": self.from_entity(entity="entidade_numeros_ramal")
                }

    def submit(self,dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict]:
        dispatcher.utter_message('Aguarde um instate. Estou personalizando o display do ramal.')
        ramal = tracker.get_slot('entidade_numeros_ramal')
        nome_display = tracker.get_slot('nome_visor')

Here is the error presented in the terminal, when FormAction is triggered. He complains about the self.validate_slots line (slot_values, dispatcher, tracker, domain)

2020-02-11 22:03:48 DEBUG    forms.como_configurar_personalizar  - Validating extracted slots: {'entidade_numeros_ramal': '7978897'}
/home/igor/RasaX/rasa1.7/lib/python3.7/site-packages/rasa_sdk/forms.py:526: RuntimeWarning: coroutine 'FormAction.validate_slots' was never awaited
  events.extend(await self._validate_if_required(dispatcher, tracker, domain))
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Exception occurred while handling uri: 'http://localhost:5055/webhook'
Traceback (most recent call last):
  File "/home/igor/RasaX/rasa1.7/lib/python3.7/site-packages/sanic/app.py", line 942, in handle_request
    response = await response
  File "/home/igor/RasaX/rasa1.7/lib/python3.7/site-packages/rasa_sdk/endpoint.py", line 86, in webhook
    result = await executor.run(action_call)
  File "/home/igor/RasaX/rasa1.7/lib/python3.7/site-packages/rasa_sdk/executor.py", line 278, in run
    events = await action(dispatcher, tracker, domain)
  File "/home/igor/RasaX/rasa1.7/lib/python3.7/site-packages/rasa_sdk/forms.py", line 526, in run
    events.extend(await self._validate_if_required(dispatcher, tracker, domain))
TypeError: 'coroutine' object is not iterable

I checked the rasa_sdk/forms.py file for versions 1.6.1 and 1.7.0, and identified that the await method exists in version 1.7.0, which did not exist in version 1.6.1.

Could someone on the team help me?

type

All 3 comments

Thanks for raising this issue, @JustinaPetr will get back to you about it soon✨

Please also check out the docs and the forum in case your issue was raised there too 🤗

Hi @igormiranda001 , if you look at the code for how the form action has changed between 1.6.1 and 1.7.0, you will see that the code has become async. E.g. the default validate function that you have overwritten is now async: https://github.com/RasaHQ/rasa-sdk/blob/master/rasa_sdk/forms.py#L326

In your code, you need to define your function with async def validate(). Then because validate_slots is also async, you should change the line where you call it like so:

return await self.validate_slots(slot_values, dispatcher, tracker, domain)

I think that should get you up and running again.

It's work! Thanks @erohmensing

Was this page helpful?
0 / 5 - 0 ratings