Exemple #1
0
def test_concerts_online_example(tmpdir):
    sys.path.append("examples/concertbot/")
    from train_online import train_agent
    from rasa_core import utils

    story_path = tmpdir.join("stories.md").strpath

    with utilities.cwd("examples/concertbot"):
        msgs = iter(["/greet", "/greet", "/greet"])
        msgs_f = functools.partial(next, msgs)

        with utilities.mocked_cmd_input(
                utils,
                text=[
                    "2",  # action is wrong
                    "5",  # choose utter_goodbye action
                    "1"  # yes, action_listen is correct.
                ] * 2 + [  # repeat this twice
                    "0",  # export
                    story_path  # file path to export to
                ]):
            agent = train_agent()

            responses = agent.handle_text("/greet", sender_id="user1")
            assert responses[-1]['text'] == "hey there!"

            online.serve_agent(agent, get_next_message=msgs_f)

            # the model should have been retrained and the model should now
            # directly respond with goodbye
            responses = agent.handle_text("/greet", sender_id="user2")
            assert responses[-1]['text'] == "goodbye :("

            assert os.path.exists(story_path)
            print(utils.read_file(story_path))

            t = training.load_data(story_path,
                                   agent.domain,
                                   use_story_concatenation=False)
            assert len(t) == 1
            assert len(t[0].events) == 9
            assert t[0].events[5] == ActionExecuted("utter_goodbye")
            assert t[0].events[6] == ActionExecuted("action_listen")
def test_concerts_online_example(tmpdir):
    sys.path.append("examples/concertbot/")
    from train_online import train_agent
    from rasa_core import utils

    story_path = tmpdir.join("stories.md").strpath

    with utilities.cwd("examples/concertbot"):
        msgs = iter(["/greet", "/greet", "/greet"])
        msgs_f = functools.partial(next, msgs)

        with utilities.mocked_cmd_input(
                utils,
                text=["2",  # action is wrong
                      "5",  # choose utter_goodbye action
                      "1"  # yes, action_listen is correct.
                      ] * 2 + [  # repeat this twice
                         "0",  # export
                         story_path  # file path to export to
                     ]):
            agent = train_agent()

            responses = agent.handle_text("/greet", sender_id="user1")
            assert responses[-1]['text'] == "hey there!"

            online.serve_agent(agent, get_next_message=msgs_f)

            # the model should have been retrained and the model should now
            # directly respond with goodbye
            responses = agent.handle_text("/greet", sender_id="user2")
            assert responses[-1]['text'] == "goodbye :("

            assert os.path.exists(story_path)
            print(utils.read_file(story_path))

            t = training.load_data(story_path, agent.domain,
                                   use_story_concatenation=False)
            assert len(t) == 1
            assert len(t[0].events) == 9
            assert t[0].events[5] == ActionExecuted("utter_goodbye")
            assert t[0].events[6] == ActionExecuted("action_listen")
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
from rasa_core import train, utils
from rasa_core.training import online

from rasa_core.interpreter import NaturalLanguageInterpreter

logger = logging.getLogger(__name__)

def train_agent(interpreter):
    return train.train_dialogue_model(domain_file="horoscope_domain.yml",
                                      stories_file="data/stories.md",
                                      output_path="models/dialog",
                                      nlu_model_path=interpreter,
                                      endpoints="endpoints.yml",
                                      max_history=2,
                                      kwargs={"batch_size": 50,
                                              "epochs": 200,
                                              "max_training_samples": 300
                                              })

if __name__ == '__main__':
    utils.configure_colored_logging(loglevel="DEBUG")
    nlu_model_path = "./models/nlu/default/horoscopebot"
    interpreter = NaturalLanguageInterpreter.create(nlu_model_path)
    agent = train_agent(interpreter)
    online.serve_agent(agent)
Exemple #4
0
    # Running as standalone python application
    arg_parser = create_argument_parser()
    cmdline_args = arg_parser.parse_args()

    utils.configure_colored_logging(cmdline_args.loglevel)

    additional_arguments = {
        "epochs": cmdline_args.epochs,
        "batch_size": cmdline_args.batch_size,
        "validation_split": cmdline_args.validation_split,
        "augmentation_factor": cmdline_args.augmentation,
        "debug_plots": cmdline_args.debug_plots
    }

    if cmdline_args.url:
        stories = utils.download_file_from_url(cmdline_args.url)
    else:
        stories = cmdline_args.stories

    a = train_dialogue_model(cmdline_args.domain,
                             stories,
                             cmdline_args.out,
                             cmdline_args.nlu,
                             cmdline_args.endpoints,
                             cmdline_args.history,
                             cmdline_args.dump_stories,
                             additional_arguments)

    if cmdline_args.online:
        online.serve_agent(a)
Exemple #5
0
    utils.configure_colored_logging(cmdline_args.loglevel)

    additional_arguments = {
        "epochs": cmdline_args.epochs,
        "batch_size": cmdline_args.batch_size,
        "validation_split": cmdline_args.validation_split,
        "augmentation_factor": cmdline_args.augmentation,
        "debug_plots": cmdline_args.debug_plots,
        "nlu_threshold": cmdline_args.nlu_threshold,
        "core_threshold": cmdline_args.core_threshold,
        "fallback_action_name": cmdline_args.fallback_action_name
    }

    if cmdline_args.url:
        stories = utils.download_file_from_url(cmdline_args.url)
    else:
        stories = cmdline_args.stories

    a = train_dialogue_model(cmdline_args.domain,
                             stories,
                             cmdline_args.out,
                             cmdline_args.nlu,
                             cmdline_args.endpoints,
                             cmdline_args.history,
                             cmdline_args.dump_stories,
                             additional_arguments)

    if cmdline_args.online:
        online.serve_agent(a)
Exemple #6
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import logging

from rasa_core import utils, train
from rasa_core.training import online

logger = logging.getLogger(__name__)


def train_agent():
    return train.train_dialogue_model(domain_file="domain.yml",
                                      stories_file="data/stories.md",
                                      output_path="models/dialogue",
                                      endpoints="endpoints.yml",
                                      max_history=2,
                                      kwargs={"batch_size": 50,
                                              "epochs": 200,
                                              "max_training_samples": 300
                                              })


if __name__ == '__main__':
    utils.configure_colored_logging(loglevel="INFO")
    agent = train_agent()
    online.serve_agent(agent)