Agent.handle_text not working properly with Rasa 1.0

Hi Tom, I’m trying to run a specific NLU server based on the language slot in the tracker. I understand that since all of Rasa code is in async mode, you can’t just call an async function any more. 2 methods are given to invoke an async function–“await” and loop.run_until_complete(). I tried the following:

current_interpreter = await self._pick_interpreter(tracker)

and

loop = asyncio.get_event_loop()

current_interpreter = loop.run_until_complete(self._pick_interpreter(tracker))

loop.close()

and

asyncio.run() that you see below, but nothing works. It looks like _pick_interpreter is not getting hit and I never get a the print statement in my output and the code just hangs. Am I missing something basic?

async def _pick_interpreter(self, tracker):

    language = tracker.get_slot('language')
    if language == 'english' :
        current_interpeteter = self.interpreter

    elif language == 'spanish' :
        current_interpreter = self.interpreter2
    else:
        current_interpeteter = self.interpreter
    print('current interpreter is', current_interpreter)
    return current_interpreter

async def _parse_message(self, message):
    # for testing - you can short-cut the NLU part with a message
    # in the format /intent{"entity1": val1, "entity2": val2}
    # parse_data is a dict of intent & entities
    print('reached here"')
    current_interpreter = asyncio.run(_pick_interpreter(tracker))
    '''loop = asyncio.get_event_loop()
    current_interpreter = loop.run_until_complete(self._pick_interpreter(tracker))
    #print('passed pick_interpreter')
    loop.close()'''

Has anyone managed to get an answer from the loaded agent that is not empty/None ? I’m facing the same issue.

Thank you

Okay it didn’t work for me for a reason that isn’t mentioned above but appears quite logic :3

You need to have the action server running “rasa run actions”, empty answers can be due to that.

Do you have to unzip your models and reference the files directly in agent then? What’s the point of a model server if you need to load the files directly into the agent?

Just wanna share my experience:

  1. First I got the same error <coroutine object Agent.handle_text at 0x133236af0> .
  2. I applied the solution proposed by @tmbo in spyder and got # RuntimeError: This event loop is already running .
  3. To solve this, I installed nest_asyncio and included import nest_asyncio
    nest_asyncio.apply()
  4. I got NoneType and checked agent.is_ready(), which was False.
  5. To solve this, I manually unzipped the model as tried out by @kothiyayogesh . And it worked.
1 Like

Were you able to fix it?

How is that? could you explain what you mean by unzipping

i need the confidence as well, but this just returns the text, any help on this?