コード例 #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")
コード例 #2
0
ファイル: test_examples.py プロジェクト: rohitjun08/rasa_core
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")
コード例 #3
0
def test_console_input():
    from rasa_core.channels import console

    # Overwrites the input() function and when someone else tries to read
    # something from the command line this function gets called.
    with utilities.mocked_cmd_input(console, text="Test Input"):
        httpretty.register_uri(httpretty.POST,
                               'https://abc.defg/webhooks/rest/webhook',
                               body='')

        httpretty.enable()
        console.record_messages(server_url="https://abc.defg",
                                max_message_limit=3)
        httpretty.disable()

        assert (httpretty.latest_requests[-1].path ==
                "/webhooks/rest/webhook?stream=true&token=")

        b = httpretty.latest_requests[-1].body.decode("utf-8")

        assert json.loads(b) == {"message": "Test Input", "sender": "default"}
コード例 #4
0
ファイル: test_channels.py プロジェクト: rohitjun08/rasa_core
def test_console_input():
    import rasa_core.channels.console

    # Overwrites the input() function and when someone else tries to read
    # something from the command line this function gets called.
    with utilities.mocked_cmd_input(rasa_core.channels.console,
                                    text="Test Input"):
        httpretty.register_uri(httpretty.POST,
                               'https://abc.defg/webhooks/rest/webhook',
                               body='')

        httpretty.enable()
        console.record_messages(
                server_url="https://abc.defg",
                max_message_limit=3)
        httpretty.disable()

        assert (httpretty.latest_requests[-1].path ==
                "/webhooks/rest/webhook?stream=true&token=")

        b = httpretty.latest_requests[-1].body.decode("utf-8")

        assert json.loads(b) == {"message": "Test Input", "sender": "default"}