Dialogue - Getting Started with Rasa / Tutorials, Resources & Videos - Rasa Community Forum

post by hajoura on Jun 6, 2019

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

import logging
from rasa_core.agent import Agent
from rasa_core.channels.console import ConsoleInputChannel
from rasa_core.interpreter import RegexInterpreter
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter

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()])
    agent.train(
        training_data_file,
        max_history=3,
        epochs=300,
        batch_size=50,
        validation_split=0.2,
        augmentation_factor=50
    )
    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)
    if serve_forever:
        agent.handle_channel(ConsoleInputChannel())
    return agent

if __name__ == '__main__':
    train_dialogue()
    run_weather_bot()

Warnings

{
  "resource": "/Users/Desktop/weath/dialogue_management_model.py",
  "owner": "python",
  "code": "no-name-in-module",
  "severity": 8,
  "message": "No name 'ConsoleInputChannel' in module 'rasa_core.channels.console'",
  "source": "pylint",
  "startLineNumber": 9,
  "startColumn": 1,
  "endLineNumber": 9,
  "endColumn": 1
}
{
  "resource": "/Users/Desktop/weath/dialogue_management_model.py",
  "owner": "python",
  "code": "no-member",
  "severity": 8,
  "message": "Instance of 'Agent' has no 'handle_channel' member; maybe 'handle_channels'?",
  "source": "pylint",
  "startLineNumber": 39,
  "startColumn": 3,
  "endLineNumber": 39,
  "endColumn": 3
}

Dependencies: