Rasa: sys:1: RuntimeWarning: coroutine 'Agent.load_data' was never awaited

Created on 28 Apr 2019  路  10Comments  路  Source: RasaHQ/rasa

Rasa version:
-e git+https://github.com/RasaHQ/rasa_core.git@41bb59fc934bb5a1ae4d8cebe412751038c3b2b9#egg=rasa
rasa-core-sdk==0.13.1
rasa-nlu==0.15.0

Python version:
Python 3.6.7

Operating system (windows, osx, ...):
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic

Issue:
I am getting following issue when I train the core model.

Traceback (most recent call last):
  File "dialogue_management_model.py", line 54, in <module>
    train_dialogue(interpreter=RasaNLUInterpreter)
  File "dialogue_management_model.py", line 37, in train_dialogue
    training_data)
  File "/home/ubuntu/rasa_stack/rasa_core/rasa/core/agent.py", line 580, in train
    **kwargs)
  File "/home/ubuntu/rasa_stack/rasa_core/rasa/core/policies/ensemble.py", line 83, in train
    policy.train(training_trackers, domain, **kwargs)
  File "/home/ubuntu/rasa_stack/rasa_core/rasa/core/policies/memoization.py", line 139, in train
    for t in training_trackers
TypeError: 'coroutine' object is not iterable
sys:1: RuntimeWarning: coroutine 'Agent.load_data' was never awaited

Please find the code in dialogue_management_model.py below:

from rasa.core.agent import Agent
from rasa.core.policies import FallbackPolicy, KerasPolicy, MemoizationPolicy, FormPolicy
from rasa.core.interpreter import RasaNLUInterpreter
from rasa.core.training import interactive
from rasa.core.utils import EndpointConfig

logger = logging.getLogger(__name__)

# this will catch predictions the model isn't very certain about
# there is a threshold for the NLU predictions as well as the action predictions
fallback = FallbackPolicy(fallback_action_name="utter_unclear",
                          core_threshold=0.2,
                          nlu_threshold=0.1)

def train_dialogue(interpreter,domain_file = 'domain.yml',
                   model_path = './models/dialogue',
                   training_data_file = './data/stories.md'):

    #action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy(), FormPolicy(), fallback])
    training_data = agent.load_data('./data/stories.md')

    agent.train(training_data)

    agent.persist('models/dialogue')
    return agent

def run_weather_bot(serve_forever=True):
    nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/current')
    action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
    agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint)
    #rasa_core.run.serve_application(agent ,channel='cmdline')

    return agent

if __name__ == '__main__':
    train_dialogue(interpreter=RasaNLUInterpreter)
    run_weather_bot()
more-details-needed

Most helpful comment

@Nomiluks -

Add the following in imports
import asyncio

Modify your code while using load_data
training_data = asyncio.run(agent.load_data('./data/stories.md'))

This has worked for me. Please let me know if this works for you too.

All 10 comments

Thanks for raising this issue, @wochinge will get back to you about it soon.

@akelad / @wochinge, please let me know if you have any update on this issue?

In the new releases we switched to use asyncio so you have to adapt your code to that, e.g. using

training_data = await agent.load_data('./data/stories.md')

If you use the current stable release of Rasa core 0.14.1 with the weather bot example.

Python 3.7.3
Rasa 1.0.0rc4

 await training_data =  agent.load_data("../data/stories.md")
    ^
SyntaxError: can't assign to await expression

This issue has been automatically closed because there has been no response to our request for more information from the original author. Without this, we don't have enough information to help you. Please comment below with the requested information if you still need help.

In the new releases we switched to use asyncio so you have to adapt your code to that, e.g. using

await training_data = agent.load_data('./data/stories.md')

If you use the current stable release of Rasa core 0.14.1 with the weather bot example.

Can you share the link of rasa weather bot example so we can upgrade accordingly. I am also facing similar errors

@Nomiluks -

Add the following in imports
import asyncio

Modify your code while using load_data
training_data = asyncio.run(agent.load_data('./data/stories.md'))

This has worked for me. Please let me know if this works for you too.

@wassimseif Thanks for catching this error, corrected my example 馃憤
@Nomiluks Sorry, the weatherbot is not an offical Rasa repository and hence I cannot say when / whether it will be updated.

@wochinge - Does Rasa 1.0+ expects the users to use CLI only? Can't we program the code from scratch like previous versions?

No 鉂楋笍 Rasa is open-source and will always stay hackable / customizable. However, we will try to make it as easy usable as possible and to make everything important configurable without having to write custom code. This also makes it easier for you to upgrade and so on.

Was this page helpful?
0 / 5 - 0 ratings