Command line bot Rasa

Hi

I’m running: Python 3.7.3, rasa 1.0.7, rasa-nlu 0.15.0 and rasa-sdk 1.0.0

I run Python and Rasa on a Dell Windows 7 desktop with 32GB RAM

I have been following a number of the on-line tutorials from various contributors, but noticed that many of the examples are 6 to 12 months old, and so when trying to implement them with the above versions of Python and Rasa I run into troubles, typically due to Rasa being updated several times since these tutorials were first written

I have managed to amend my code to sort out most issues, but I can’t seem to complete the dialogue_management_model, particularly I can’t get the command line bot to work. I thin the train_dialogue routine is fine as that seems to work.

All the examples I have seen for run_bot use commands that are now deprecated, and I can’t find the current alternative methods. What should I do to get the code to run correctly?

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging
import os
import asyncio

from rasa.core.agent import Agent
from rasa.core.interpreter import RasaNLUInterpreter
from rasa.core.policies import KerasPolicy, MemoizationPolicy
from rasa.utils.endpoints import EndpointConfig
from bot_constants import NLU_MODELS_DIR, BOT_NAME
from rasa.core.train import online

logger = logging.getLogger(__name__)

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

    agent = Agent(domain_file, policies = [MemoizationPolicy(max_history = 5),
                                       KerasPolicy(max_history = 3,
                                                   epochs = 300,
                                                   batch_size = 50,
                                                   validation_split = 0.2,
                                                   augmentation_factor=50)])



      training_data = await agent.load_data(training_data_file)

     agent.train(training_data)

     agent.persist(model_path)

     return agent

def run_bot(serve_forever = True):
    interpreter = RasaNLUInterpreter(os.path.join(NLU_MODELS_DIR + '/' + BOT_NAME))
    action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")
    agent = Agent.load('./models/dialogue', interpreter=interpreter, action_endpoint=action_endpoint)
    if serve_forever:
       #None of the following methods appear to work
        online.serve_agent(agent)
        #channel = BotServerInputChannel(agent)
        #agent.handle_channel(channel)
        #agent.handle_channels([channel])  

        #I think agent.handle_channels(channel) expects an array of channels. Try agent.handle_channels([channel])
        #agent.handle_channel(ConsoleInputChannel())
    #rasa_core.run.serve_application(agent, channel='cmdline')
	
    return agent


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(train_dialogue())
    run_bot()

Hi @JohannesKann,

Why do you want to run the bot using the Python API specifically? As far as I can tell, you should be able to achieve the same thing using rasa train and rasa run.

Anyway, to help with your queries you can consult the rasa_core migrations docs from the old repo, but I think await agent.handle_channels([ConsoleInputChannel()]) should work here.