from future import absolute_import
from future import division
from future import print_function
from future import unicode_literals
import os
import logging
import rasa_core
#from rasa_core import utils, server
#from rasa_core import constants, agent
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.utils import EndpointConfig
from rasa_core.run import serve_application
#from rasa_core.channels import HttpInputChannel
#from rasa_core.agent import Agent
#from rasa_core.interpreter import RasaNLUInterpreter
#from rasa_slack_connector import SlackInput
from bot_server_channel import BotServerInputChannel
logger = logging.getLogger(name)
def train_dialogue(domain_file = ‘troubleshoot_domain.yml’,
model_path = ‘./models/dialogue’,
training_data_file = ‘./data/stories.md’):
agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy()])
data = agent.load_data(training_data_file)
agent.train(
data,
epochs = 300,
batch_size = 50,
validation_split = 0.2)
agent.persist(model_path)
return agent
Creating the Interpreter and Agent
def load_agent():
nlu_interpreter = RasaNLUInterpreter(’./models/nlu/default/troubleshootnlu’)
agent = Agent.load(’./models/dialogue’, interpreter = nlu_interpreter)
Creating the server
def main_server():
agent = load_agent()
channel = BotServerInputChannel(agent, port=5002)
agent.handle_channels([channel], http_port=5002, serve_forever=True)
‘’’
def run_bot(serve_forever=True):
interpreter = RasaNLUInterpreter(’./models/nlu/default/troubleshootnlu’)
agent = Agent.load(’./models/dialogue’, interpreter=interpreter)
rasa_core.run.serve_application(agent ,channel=‘cmdline’)
return agent
‘’’
if name == ‘main’:
train_dialogue()
#run_bot()
main_server()