TypeError: 'coroutine' object is not iterable
See original GitHub issueRasa version:
rasa 1.0.2
rasa-core-sdk 0.14.0
rasa-sdk 1.0.0
Python version: Python 3.7.3
Operating system (windows, osx, …): Mac osx Mojave
Issue: When I run the below command: python dialogue_management_model.py
The error that pops up is this frame below:
WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0. For more information, please see:
- https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
- https://github.com/tensorflow/addons If you depend on functionality not listed there, please file an issue.
Traceback (most recent call last): File “dialogue_management_model.py”, line 38, in <module> train_dialogue() File “dialogue_management_model.py”, line 25, in train_dialogue agent.train(data) File “/usr/local/lib/python3.7/site-packages/rasa/core/agent.py”, line 668, in train self.policy_ensemble.train(training_trackers, self.domain, **kwargs) File “/usr/local/lib/python3.7/site-packages/rasa/core/policies/ensemble.py”, line 89, in train policy.train(training_trackers, domain, **kwargs) File “/usr/local/lib/python3.7/site-packages/rasa/core/policies/memoization.py”, line 152, in train for t in training_trackers TypeError: ‘coroutine’ object is not iterable sys:1: RuntimeWarning: coroutine ‘Agent.load_data’ was never awaited
I’m unsure of how this is happening, and I saw on another post to add “await” before when i train the agent, but that gave a syntax error. Please help!!
Content of configuration file (config.yml):
{
"pipeline":"spacy_sklearn",
"path":"./models/nlu",
"data":"./data/data.json"
}
Content of domain file (domain.yml):
slots:
location:
type: text
intents:
- greet
- goodbye
- inform
entities:
- location
templates:
utter_greet:
- 'Hello! How can I help you today?'
- 'Hi there!'
utter_goodbye:
- 'Goodbye! I hope I was of assistance today :)'
- 'Bye bye!'
- 'See you later!'
utter_ask_location:
- 'Could you specify the location?'
- 'In what location?'
- 'Where, exactly?'
actions:
- utter_greet
- utter_goodbye
- utter_ask_location
- action_weather
Content of dialogue_management_model.py:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
import rasa.core
from rasa.core.agent import Agent
from rasa.core.policies.keras_policy import KerasPolicy
from rasa.core.policies.memoization import MemoizationPolicy
from rasa.core.interpreter import RasaNLUInterpreter
from rasa.core.run import serve_application
from rasa.core import config
logger = logging.getLogger(__name__)
def train_dialogue(domain_file = 'weather_domain.yml',
model_path = './models/dialogue',
training_data_file = './data/stories.md'):
agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(max_history=3, epochs=200, batch_size=50)])
data = agent.load_data(training_data_file)
agent.train(data)
agent.persist(model_path)
return agent
def run_weather_bot(serve_forever=True):
interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu')
agent = Agent.load('./models/dialogue', interpreter=interpreter)
rasa.core.run.serve_application(agent ,channel='cmdline')
return agent
if __name__ == '__main__':
train_dialogue()
run_weather_bot()
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:16 (7 by maintainers)
Top GitHub Comments
We use asyncio internally.
agent.load_data
is a coroutine that needs to be run and waited for. Please try out the following code:As you are using python3.7 you should be able to replace
by
@neerajb1 As soon as you put the keyword
async
to the function definition, it becomes a coroutine. If you notawait
the coroutine, the error you mentioned will show up.In your case you can simply remove the keyword
async
fromtrain_dialogue
as it is not needed. Please have a look at https://docs.python.org/3/library/asyncio-task.html#coroutine for more information.Try the following: