Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1743 from RasaHQ/rasa-cli
Browse files Browse the repository at this point in the history
Rasa cli
  • Loading branch information
wochinge authored Mar 6, 2019
2 parents 02b8642 + 8fc8cfa commit d21373c
Show file tree
Hide file tree
Showing 36 changed files with 1,178 additions and 1,073 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ Added
for tensorflow based pipelines
- open api spec for the Rasa Core SDK action server
- documentation about early deactivation of a form in validation
- utility functions for colored logging
- open webbrowser when visualizing stories
- added ability to use multiple env vars per line in yaml files

Changed
-------
- starter packs are now tested in parallel with the unittests,
and only on master and branches ending in ``.x`` (i.e. new version releases)
- renamed ``train_dialogue_model`` to ``train``
- renamed ``rasa_core.evaluate`` to ``rasa_core.test``
- ``scores`` array returned by the ``/conversations/{sender_id}/predict``
endpoint is now sorted according to the actions' scores.

Expand Down
14 changes: 14 additions & 0 deletions docs/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ Migration Guide
This page contains information about changes between major versions and
how you can migrate from one version to another.


.. _migration-to-0-14-0:

0.13.x to 0.14.0
----------------

Function Naming
~~~~~~~~~~~~~~~
- renamed ``train_dialogue_model`` to ``train``. Please use ``train`` from
now on.
- renamed ``rasa_core.evaluate`` to ``rasa_core.test``. Please use ``test``
from now on.


.. _migration-to-0-13-0:

0.12.x to 0.13.0
Expand Down
12 changes: 5 additions & 7 deletions examples/concertbot/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ def train_dialogue(domain_file='domain.yml',
stories_file='data/stories.md',
model_path='models/dialogue',
policy_config='policy_config.yml'):
return train.train_dialogue_model(domain_file=domain_file,
stories_file=stories_file,
output_path=model_path,
policy_config=policy_config,
kwargs={'augmentation_factor': 50,
'validation_split': 0.2}
)
return train(domain_file=domain_file,
stories_file=stories_file,
output_path=model_path,
policy_config=policy_config,
kwargs={'augmentation_factor': 50, 'validation_split': 0.2})


if __name__ == '__main__':
Expand Down
9 changes: 4 additions & 5 deletions examples/concertbot/train_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@


def train_agent():
return train.train_dialogue_model(domain_file="domain.yml",
stories_file="data/stories.md",
output_path="models/dialogue",
policy_config='policy_config.yml'
)
return train(domain_file="domain.yml",
stories_file="data/stories.md",
output_path="models/dialogue",
policy_config='policy_config.yml')


if __name__ == '__main__':
Expand Down
4 changes: 4 additions & 0 deletions rasa_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import rasa_core.version

from rasa_core.train import train
from rasa_core.test import test
from rasa_core.visualize import visualize

logging.getLogger(__name__).addHandler(logging.NullHandler())

__version__ = rasa_core.version.__version__
23 changes: 5 additions & 18 deletions rasa_core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from threading import Thread
from typing import Text, List, Optional, Callable, Any, Dict, Union

import rasa_core
from rasa_core import training, constants
from rasa_core.channels import UserMessage, OutputChannel, InputChannel
from rasa_core.constants import DEFAULT_REQUEST_TIMEOUT
Expand Down Expand Up @@ -200,18 +199,7 @@ def __init__(
"FormPolicy to your policy ensemble."
)

if not isinstance(interpreter, NaturalLanguageInterpreter):
if interpreter is not None:
logger.warning(
"Passing a value for interpreter to an agent "
"where the value is not an interpreter "
"is deprecated. Construct the interpreter, before"
"passing it to the agent, e.g. "
"`interpreter = NaturalLanguageInterpreter.create("
"nlu)`.")
interpreter = NaturalLanguageInterpreter.create(interpreter, None)

self.interpreter = interpreter
self.interpreter = NaturalLanguageInterpreter.create(interpreter)

self.nlg = NaturalLanguageGenerator.create(generator, self.domain)
self.tracker_store = self.create_tracker_store(
Expand Down Expand Up @@ -348,7 +336,7 @@ def handle_text(
message_preprocessor: Optional[Callable[[Text], Text]] = None,
output_channel: Optional[OutputChannel] = None,
sender_id: Optional[Text] = UserMessage.DEFAULT_SENDER_ID
) -> Optional[List[Text]]:
) -> Optional[List[Dict[Text, Any]]]:
"""Handle a single message.
If a message preprocessor is passed, the message will be passed to that
Expand Down Expand Up @@ -530,6 +518,7 @@ def handle_channels(self, channels: List[InputChannel],
Otherwise the webserver will be started, and the method will
return afterwards."""
from flask import Flask
import rasa_core

app = Flask(__name__)
rasa_core.channels.channel.register(channels,
Expand Down Expand Up @@ -613,8 +602,7 @@ def visualize(self,
max_history, self.interpreter,
nlu_training_data, should_merge_nodes, fontsize)

def _ensure_agent_is_ready(self):
# type: () -> None
def _ensure_agent_is_ready(self) -> None:
"""Checks that an interpreter and a tracker store are set.
Necessary before a processor can be instantiated from this agent.
Expand Down Expand Up @@ -680,8 +668,7 @@ def _create_ensemble(
"of type '{}', but should be policy, an array of "
"policies, or a policy ensemble".format(passed_type))

def _form_policy_not_present(self):
# type: () -> bool
def _form_policy_not_present(self) -> bool:
"""Check whether form policy is not present
if there is a form action in the domain
"""
Expand Down
12 changes: 4 additions & 8 deletions rasa_core/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import rasa_core.cli.arguments
from rasa_core import utils


def stories_from_cli_args(cmdline_arguments):
if cmdline_arguments.url:
return utils.download_file_from_url(cmdline_arguments.url)
else:
return cmdline_arguments.stories
import rasa_core.cli.test
import rasa_core.cli.run
import rasa_core.cli.train
import rasa_core.cli.visualization
33 changes: 33 additions & 0 deletions rasa_core/cli/arguments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

import pkg_resources


Expand Down Expand Up @@ -66,3 +68,34 @@ def add_model_and_story_group(parser, allow_pretrained_model=True):

if allow_pretrained_model:
add_core_model_arg(group)


def add_logging_option_arguments(parser):
"""Add options to an argument parser to configure logging levels."""

logging_arguments = parser.add_argument_group('Python Logging Options')

# arguments for logging configuration
logging_arguments.add_argument(
'-v', '--verbose',
help="Be verbose. Sets logging level to INFO",
action="store_const",
dest="loglevel",
const=logging.INFO,
default=logging.INFO,
)
logging_arguments.add_argument(
'-vv', '--debug',
help="Print lots of debugging statements. "
"Sets logging level to DEBUG",
action="store_const",
dest="loglevel",
const=logging.DEBUG,
)
logging_arguments.add_argument(
'--quiet',
help="Be quiet! Sets logging level to WARNING",
action="store_const",
dest="loglevel",
const=logging.WARNING,
)
59 changes: 59 additions & 0 deletions rasa_core/cli/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from rasa_core import constants


def add_run_arguments(parser):
server_arguments = parser.add_argument_group("Server Settings")
server_arguments.add_argument(
'-p', '--port',
default=constants.DEFAULT_SERVER_PORT,
type=int,
help="port to run the server at")
server_arguments.add_argument(
'--auth_token',
type=str,
help="Enable token based authentication. Requests need to provide "
"the token to be accepted.")
server_arguments.add_argument(
'--cors',
nargs='*',
type=str,
help="enable CORS for the passed origin. "
"Use * to whitelist all origins")
server_arguments.add_argument(
'--enable_api',
action="store_true",
help="Start the web server api in addition to the input channel")

parser.add_argument(
'-o', '--log_file',
type=str,
default="rasa_core.log",
help="store log file in specified file")
channel_arguments = parser.add_argument_group("Channels")
channel_arguments.add_argument(
'--credentials',
default=None,
help="authentication credentials for the connector as a yml file")
channel_arguments.add_argument(
'-c', '--connector',
type=str,
help="service to connect to")
parser.add_argument(
'--endpoints',
default=None,
help="Configuration file for the connectors as a yml file")

jwt_auth = parser.add_argument_group('JWT Authentication')
jwt_auth.add_argument(
'--jwt_secret',
type=str,
help="Public key for asymmetric JWT methods or shared secret"
"for symmetric methods. Please also make sure to use "
"--jwt_method to select the method of the signature, "
"otherwise this argument will be ignored.")
jwt_auth.add_argument(
'--jwt_method',
type=str,
default="HS256",
help="Method used for the signature of the JWT authentication "
"payload.")
35 changes: 35 additions & 0 deletions rasa_core/cli/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from rasa_core.cli import arguments


def add_evaluation_arguments(parser):
parser.add_argument(
'-m', '--max_stories',
type=int,
help="maximum number of stories to test on")
parser.add_argument(
'-u', '--nlu',
type=str,
help="nlu model to run with the server. None for regex interpreter")
parser.add_argument(
'-o', '--output',
type=str,
default="results",
help="output path for the any files created from the evaluation")
parser.add_argument(
'--e2e', '--end-to-end',
action='store_true',
help="Run an end-to-end evaluation for combined action and "
"intent prediction. Requires a story file in end-to-end "
"format.")
parser.add_argument(
'--endpoints',
default=None,
help="Configuration file for the connectors as a yml file")
parser.add_argument(
'--fail_on_prediction_errors',
action='store_true',
help="If a prediction error is encountered, an exception "
"is thrown. This can be used to validate stories during "
"tests, e.g. on travis.")

arguments.add_core_model_arg(parser)
Loading

0 comments on commit d21373c

Please sign in to comment.