From f5546870af10a6bc63253d9a081d810243e70259 Mon Sep 17 00:00:00 2001 From: Tom Bocklisch Date: Mon, 13 May 2019 12:24:10 +0200 Subject: [PATCH] renamed package --- .github/ISSUE_TEMPLATE.md | 4 +- .travis.yml | 2 +- Makefile | 2 +- README.md | 29 +++++--- entrypoint.sh | 8 +-- rasa_sdk/__init__.py | 20 ++++++ rasa_sdk/__main__.py | 26 +++++++ {rasa_core_sdk => rasa_sdk}/cli/__init__.py | 0 {rasa_core_sdk => rasa_sdk}/cli/arguments.py | 2 +- {rasa_core_sdk => rasa_sdk}/constants.py | 0 {rasa_core_sdk => rasa_sdk}/endpoint.py | 68 ++++++++----------- {rasa_core_sdk => rasa_sdk}/events.py | 0 {rasa_core_sdk => rasa_sdk}/executor.py | 7 +- {rasa_core_sdk => rasa_sdk}/forms.py | 8 +-- .../__init__.py => rasa_sdk/interfaces.py | 19 ++---- {rasa_core_sdk => rasa_sdk}/utils.py | 0 {rasa_core_sdk => rasa_sdk}/version.py | 0 setup.py | 10 +-- tests/test_actions.py | 6 +- tests/test_endpoint.py | 2 +- tests/test_forms.py | 8 +-- tests/test_tracker.py | 4 +- 22 files changed, 132 insertions(+), 93 deletions(-) create mode 100644 rasa_sdk/__init__.py create mode 100644 rasa_sdk/__main__.py rename {rasa_core_sdk => rasa_sdk}/cli/__init__.py (100%) rename {rasa_core_sdk => rasa_sdk}/cli/arguments.py (93%) rename {rasa_core_sdk => rasa_sdk}/constants.py (100%) rename {rasa_core_sdk => rasa_sdk}/endpoint.py (63%) rename {rasa_core_sdk => rasa_sdk}/events.py (100%) rename {rasa_core_sdk => rasa_sdk}/executor.py (96%) rename {rasa_core_sdk => rasa_sdk}/forms.py (99%) rename rasa_core_sdk/__init__.py => rasa_sdk/interfaces.py (94%) rename {rasa_core_sdk => rasa_sdk}/utils.py (100%) rename {rasa_core_sdk => rasa_sdk}/version.py (100%) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index ec48868a4..185ebcb9a 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,6 +1,6 @@ - + -**Rasa Core SDK version**: +**Rasa SDK version**: **Python version**: diff --git a/.travis.yml b/.travis.yml index 9b46ea26b..7e62fd20d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: - pip install coveralls==1.3.0 - pip list script: -- travis_wait py.test tests --cov rasa_core_sdk -v +- travis_wait py.test tests --cov rasa_sdk -v after_success: - coveralls jobs: diff --git a/Makefile b/Makefile index 276a013b4..682fb2585 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ help: @echo " test" @echo " Run py.test" @echo " init" - @echo " Install Rasa Core" + @echo " Install Rasa SDK dependencies" init: pip install -r requirements.txt diff --git a/README.md b/README.md index 06d67e553..1952d2c7a 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,46 @@ # Rasa Python-SDK [![Join the chat on Rasa Community Forum](https://img.shields.io/badge/forum-join%20discussions-brightgreen.svg)](https://forum.rasa.com/?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -[![Build Status](https://travis-ci.com/RasaHQ/rasa_core_sdk.svg?branch=master)](https://travis-ci.com/RasaHQ/rasa_core_sdk) -[![PyPI version](https://img.shields.io/pypi/v/rasa_core_sdk.svg)](https://pypi.python.org/pypi/rasa-core-sdk) +[![Build Status](https://travis-ci.com/RasaHQ/rasa-sdk.svg?branch=master)](https://travis-ci.com/RasaHQ/rasa-sdk) +[![PyPI version](https://img.shields.io/pypi/v/rasa-sdk.svg)](https://pypi.python.org/pypi/rasa-sdk) [![Documentation Status](https://img.shields.io/badge/docs-stable-brightgreen.svg)](https://rasa.com/docs) -Python SDK for the development of custom actions for Rasa Core. +Python SDK for the development of custom actions for Rasa. ## Installation To install the SDK run ```bash -pip install rasa_core_sdk +pip install rasa-sdk ``` ## Compatibility +`rasa-sdk` package: + +| SDK version | compatible Rasa version | +|----------------|-----------------------------------| +| `1.0.x` | `>=1.0.x` | + +old `rasa_core_sdk` package: + | SDK version | compatible Rasa Core version | |----------------|----------------------------------------| -| `1.0.x` | `>=1.0.x` | | `0.12.x` | `>=0.12.x` | | `0.11.x` | `0.11.x` | | not compatible | `<=0.10.x` | ## Usage -Detailed instructions can be found in the Rasa Core Documentation about -[Custom Actions](https://rasa.com/docs/core/customactions). +Detailed instructions can be found in the Rasa Documentation about +[Custom Actions](https://rasa.com/docs/customactions). ## Docker ### Usage In order to start an action server using implemented custom actions, -you can use the available Docker image `rasa/rasa_core_sdk:latest`. +you can use the available Docker image `rasa/rasa-sdk:latest`. Before starting the action server ensure that the folder containing your actions is handled as Python module and therefore has to contain @@ -43,7 +50,7 @@ Then start the action server using: ```bash docker run -p 5055:5055 --mount type=bind,source=,target=/app/actions \ - rasa/rasa_core_sdk:latest + rasa/rasa-sdk:latest ``` The action server is then available at `http://localhost:5055/webhook`. @@ -53,7 +60,7 @@ The action server is then available at `http://localhost:5055/webhook`. To add custom dependencies you enhance the given Docker image, e.g.: ``` -FROM rasa/rasa_core_sdk:latest +FROM rasa/rasa-sdk:latest # To install system dependencies RUN apt-get update -qq && \ @@ -86,4 +93,4 @@ Technologies GmbH. [Copy of the license](LICENSE.txt). A list of the Licenses of the dependencies of the project can be found at the bottom of the -[Libraries Summary](https://libraries.io/github/RasaHQ/rasa_core_sdk). +[Libraries Summary](https://libraries.io/github/RasaHQ/rasa-sdk). diff --git a/entrypoint.sh b/entrypoint.sh index 6a3c5d5f9..2f32716f9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,14 +4,14 @@ set -Eeuo pipefail function print_help { echo "Available options:" - echo " start commands (Rasa Core cmdline arguments) - Start Rasa Core Action Server" - echo " help - Print this help" - echo " run - Run an arbitrary command inside the container" + echo " start - Start Rasa Action Server" + echo " help - Print this help" + echo " run - Run an arbitrary command inside the container" } case ${1} in start) - exec python -m rasa_core_sdk.endpoint "${@:2}" + exec python -m rasa_sdk "${@:2}" ;; run) exec "${@:2}" diff --git a/rasa_sdk/__init__.py b/rasa_sdk/__init__.py new file mode 100644 index 000000000..4f5cf43b1 --- /dev/null +++ b/rasa_sdk/__init__.py @@ -0,0 +1,20 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import logging + +import rasa_sdk.version + +logger = logging.getLogger(__name__) + +__version__ = rasa_sdk.version.__version__ + +import rasa_sdk.cli +from rasa_sdk.interfaces import Tracker, Action, ActionExecutionRejection + + +if __name__ == "__main__": + import rasa_sdk.__main__ + rasa_sdk.__main__.main() diff --git a/rasa_sdk/__main__.py b/rasa_sdk/__main__.py new file mode 100644 index 000000000..a3698cfd8 --- /dev/null +++ b/rasa_sdk/__main__.py @@ -0,0 +1,26 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import logging + +from rasa_sdk import utils +from rasa_sdk.endpoint import create_argument_parser, run + + +def main(): + # Running as standalone python application + arg_parser = create_argument_parser() + cmdline_args = arg_parser.parse_args() + + logging.basicConfig(level=logging.DEBUG) + logging.getLogger("matplotlib").setLevel(logging.WARN) + + utils.configure_colored_logging(cmdline_args.loglevel) + + run(cmdline_args.actions, cmdline_args.port, cmdline_args.cors) + + +if __name__ == '__main__': + main() diff --git a/rasa_core_sdk/cli/__init__.py b/rasa_sdk/cli/__init__.py similarity index 100% rename from rasa_core_sdk/cli/__init__.py rename to rasa_sdk/cli/__init__.py diff --git a/rasa_core_sdk/cli/arguments.py b/rasa_sdk/cli/arguments.py similarity index 93% rename from rasa_core_sdk/cli/arguments.py rename to rasa_sdk/cli/arguments.py index 7c554e82e..24fa7e579 100644 --- a/rasa_core_sdk/cli/arguments.py +++ b/rasa_sdk/cli/arguments.py @@ -1,6 +1,6 @@ import argparse -from rasa_core_sdk.constants import DEFAULT_SERVER_PORT +from rasa_sdk.constants import DEFAULT_SERVER_PORT def action_arg(action): diff --git a/rasa_core_sdk/constants.py b/rasa_sdk/constants.py similarity index 100% rename from rasa_core_sdk/constants.py rename to rasa_sdk/constants.py diff --git a/rasa_core_sdk/endpoint.py b/rasa_sdk/endpoint.py similarity index 63% rename from rasa_core_sdk/endpoint.py rename to rasa_sdk/endpoint.py index 31f4b8923..5483c2d2d 100644 --- a/rasa_core_sdk/endpoint.py +++ b/rasa_sdk/endpoint.py @@ -12,13 +12,13 @@ from flask_cors import CORS, cross_origin from gevent.pywsgi import WSGIServer -from rasa_core_sdk.cli.arguments import add_endpoint_arguments -from rasa_core_sdk.constants import DEFAULT_SERVER_PORT -from rasa_core_sdk.executor import ActionExecutor -from rasa_core_sdk import ActionExecutionRejection -import rasa_core_sdk +from rasa_sdk.cli.arguments import add_endpoint_arguments +from rasa_sdk.constants import DEFAULT_SERVER_PORT +from rasa_sdk.executor import ActionExecutor +from rasa_sdk.interfaces import ActionExecutionRejection +import rasa_sdk -from rasa_core_sdk import utils +from rasa_sdk import utils logger = logging.getLogger(__name__) @@ -69,48 +69,48 @@ def webhook(): return app -def check_version_compatibility(core_version): - """Check if the version of rasa_core and rasa_core_sdk are compatible. +def check_version_compatibility(rasa_version): + """Check if the version of rasa and rasa_sdk are compatible. The version check relies on the version string being formatted as 'x.y.z' and compares whether the numbers x and y are the same for both - rasa_core and rasa_core_sdk. + rasa and rasa_sdk. Args: - core_version - A string containing the version of rasa_core that + rasa_version - A string containing the version of rasa that is making the call to the action server. Raises: - Warning - The version of rasa_core version unkown or not compatible with - this version of rasa_core_sdk. + Warning - The version of rasa version unknown or not compatible with + this version of rasa_sdk. """ - # Check for versions of core that are too old to report their version number - if core_version is None: + # Check for versions of Rasa that are too old to report their version number + if rasa_version is None: logger.warning( - "You are using an old version of rasa_core which might " - "not be compatible with this version of rasa_core_sdk " + "You are using an old version of rasa which might " + "not be compatible with this version of rasa_sdk " "({}).\n" "To ensure compatibility use the same version " "for both, modulo the last number, i.e. using version " "A.B.x the numbers A and B should be identical for " - "both rasa_core and rasa_core_sdk." - "".format(rasa_core_sdk.__version__) + "both rasa and rasa_sdk." + "".format(rasa_sdk.__version__) ) return - core = core_version.split(".")[:-1] - sdk = rasa_core_sdk.__version__.split(".")[:-1] + rasa = rasa_version.split(".")[:-1] + sdk = rasa_sdk.__version__.split(".")[:-1] - if core != sdk: + if rasa != sdk: logger.warning( "Your versions of rasa_core and " - "rasa_core_sdk might not be compatible. You " - "are currently running rasa_core version {} " - "and rasa_core_sdk version {}.\n" + "rasa_sdk might not be compatible. You " + "are currently running rasa version {} " + "and rasa_sdk version {}.\n" "To ensure compatibility use the same " "version for both, modulo the last number, " "i.e. using version A.B.x the numbers A and " "B should be identical for " - "both rasa_core and rasa_core_sdk." - "".format(core_version, rasa_core_sdk.__version__) + "both rasa and rasa_sdk." + "".format(rasa_version, rasa_sdk.__version__) ) @@ -126,18 +126,6 @@ def run(actions, port=DEFAULT_SERVER_PORT, cors="*"): http_server.serve_forever() -def main(args): - logging.basicConfig(level=logging.DEBUG) - logging.getLogger("matplotlib").setLevel(logging.WARN) - - utils.configure_colored_logging(args.loglevel) - - run(args.actions, args.port, args.cors) - - if __name__ == "__main__": - # Running as standalone python application - arg_parser = create_argument_parser() - cmdline_args = arg_parser.parse_args() - - main(cmdline_args) + import rasa_sdk.__main__ + rasa_sdk.__main__.main() diff --git a/rasa_core_sdk/events.py b/rasa_sdk/events.py similarity index 100% rename from rasa_core_sdk/events.py rename to rasa_sdk/events.py diff --git a/rasa_core_sdk/executor.py b/rasa_sdk/executor.py similarity index 96% rename from rasa_core_sdk/executor.py rename to rasa_sdk/executor.py index a061bb42d..6e5c02fc5 100644 --- a/rasa_core_sdk/executor.py +++ b/rasa_sdk/executor.py @@ -12,7 +12,8 @@ import six from typing import Text, List, Dict, Any -from rasa_core_sdk import utils, Action, Tracker +from rasa_sdk import utils +from rasa_sdk.interfaces import Action, Tracker logger = logging.getLogger(__name__) @@ -122,7 +123,7 @@ def __init__(self): def register_action(self, action): if inspect.isclass(action): - if action.__module__.startswith("rasa_core."): + if action.__module__.startswith("rasa."): logger.warning("Skipping built in Action {}.".format(action)) return else: @@ -182,6 +183,8 @@ def register_package(self, package): abstract = getattr(meta, "abstract", False) if ( not action.__module__.startswith("rasa_core.") + and not action.__module__.startswith("rasa.") + and not action.__module__.startswith("rasa_sdk.") and not action.__module__.startswith("rasa_core_sdk.") and not abstract ): diff --git a/rasa_core_sdk/forms.py b/rasa_sdk/forms.py similarity index 99% rename from rasa_core_sdk/forms.py rename to rasa_sdk/forms.py index 11b0504d6..a064f4ac1 100644 --- a/rasa_core_sdk/forms.py +++ b/rasa_sdk/forms.py @@ -8,14 +8,14 @@ import typing from typing import Dict, Text, Any, List, Union, Optional, Tuple -from rasa_core_sdk import Action, ActionExecutionRejection -from rasa_core_sdk.events import SlotSet, Form +from rasa_sdk.interfaces import Action, ActionExecutionRejection +from rasa_sdk.events import SlotSet, Form logger = logging.getLogger(__name__) if typing.TYPE_CHECKING: - from rasa_core_sdk import Tracker - from rasa_core_sdk.executor import CollectingDispatcher + from rasa_sdk import Tracker + from rasa_sdk.executor import CollectingDispatcher # this slot is used to store information needed # to do the form handling diff --git a/rasa_core_sdk/__init__.py b/rasa_sdk/interfaces.py similarity index 94% rename from rasa_core_sdk/__init__.py rename to rasa_sdk/interfaces.py index 875b75362..7cc8bef05 100644 --- a/rasa_core_sdk/__init__.py +++ b/rasa_sdk/interfaces.py @@ -5,20 +5,14 @@ import copy import logging - import typing -from typing import Dict, Text, Any, Optional, Iterator, List +from typing import Any, Dict, Iterator, List, Optional, Text -import rasa_core_sdk.version -import rasa_core_sdk.cli +if typing.TYPE_CHECKING: + from rasa_sdk.executor import CollectingDispatcher logger = logging.getLogger(__name__) -__version__ = rasa_core_sdk.version.__version__ - -if typing.TYPE_CHECKING: - from rasa_core_sdk.executor import CollectingDispatcher - class Tracker(object): """Maintains the state of a conversation.""" @@ -125,6 +119,7 @@ def get_latest_input_channel(self): for e in reversed(self.events): if e.get("event") == "user": return e.get("input_channel") + return None def is_paused(self): # type: () -> bool @@ -192,17 +187,17 @@ def run( dispatcher (CollectingDispatcher): the dispatcher which is used to send messages back to the user. Use ``dipatcher.utter_message()`` or any other - ``rasa_core_sdk.executor.CollectingDispatcher`` + ``rasa_sdk.executor.CollectingDispatcher`` method. tracker (Tracker): the state tracker for the current user. You can access slot values using ``tracker.get_slot(slot_name)``, the most recent user message is ``tracker.latest_message.text`` and any other - ``rasa_core_sdk.Tracker`` property. + ``rasa_sdk.Tracker`` property. domain (Dict[Text, Any]): the bot's domain Returns: List[Dict[Text, Any]]: A dictionary of - ``rasa_core_sdk.events.Event`` instances that is + ``rasa_sdk.events.Event`` instances that is returned through the endpoint """ diff --git a/rasa_core_sdk/utils.py b/rasa_sdk/utils.py similarity index 100% rename from rasa_core_sdk/utils.py rename to rasa_sdk/utils.py diff --git a/rasa_core_sdk/version.py b/rasa_sdk/version.py similarity index 100% rename from rasa_core_sdk/version.py rename to rasa_sdk/version.py diff --git a/setup.py b/setup.py index d0d3c8050..86c0a45dc 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ # Avoids IDE errors, but actual version is read from version.py __version__ = None -exec (open("rasa_core_sdk/version.py").read()) +exec (open("rasa_sdk/version.py").read()) # Get the long description from the README file with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f: @@ -28,7 +28,7 @@ extras_requires = {"test": tests_requires, ":python_version < '3.5'": ["typing~=3.0"]} setup( - name="rasa-core-sdk", + name="rasa-sdk", classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", @@ -59,12 +59,12 @@ "botkit rasa conversational-agents conversational-ai chatbot" "chatbot-framework bot-framework", url="https://rasa.com", - download_url="https://github.com/RasaHQ/rasa_core_sdk/archive/{}.tar.gz" + download_url="https://github.com/RasaHQ/rasa-sdk/archive/{}.tar.gz" "".format(__version__), project_urls={ - "Bug Reports": "https://github.com/rasahq/rasa_core_sdk/issues", + "Bug Reports": "https://github.com/rasahq/rasa-sdk/issues", "Documentation": "https://rasa.com/docs", - "Source": "https://github.com/rasahq/rasa_core_sdk", + "Source": "https://github.com/rasahq/rasa-sdk", }, ) diff --git a/tests/test_actions.py b/tests/test_actions.py index e85019161..8dacc83db 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -3,9 +3,9 @@ from __future__ import print_function from __future__ import unicode_literals -from rasa_core_sdk import Action, Tracker -from rasa_core_sdk.events import SlotSet -from rasa_core_sdk.executor import ActionExecutor, CollectingDispatcher +from rasa_sdk import Action, Tracker +from rasa_sdk.events import SlotSet +from rasa_sdk.executor import ActionExecutor, CollectingDispatcher class CustomActionBase(Action): diff --git a/tests/test_endpoint.py b/tests/test_endpoint.py index 47ac6620a..37bbf78b5 100644 --- a/tests/test_endpoint.py +++ b/tests/test_endpoint.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import pytest -import rasa_core_sdk.endpoint as ep +import rasa_sdk.endpoint as ep def test_arg_parser_actions_params_folder_style(): diff --git a/tests/test_forms.py b/tests/test_forms.py index 1fdb2112c..bad776e79 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -4,10 +4,10 @@ from __future__ import unicode_literals import pytest -from rasa_core_sdk.forms import FormAction -from rasa_core_sdk import Tracker, ActionExecutionRejection -from rasa_core_sdk.executor import CollectingDispatcher -from rasa_core_sdk.events import SlotSet, Form +from rasa_sdk.forms import FormAction +from rasa_sdk import Tracker, ActionExecutionRejection +from rasa_sdk.executor import CollectingDispatcher +from rasa_sdk.events import SlotSet, Form def test_extract_requested_slot_default(): diff --git a/tests/test_tracker.py b/tests/test_tracker.py index c67b6b32d..5aa42928f 100644 --- a/tests/test_tracker.py +++ b/tests/test_tracker.py @@ -3,8 +3,8 @@ from __future__ import print_function from __future__ import unicode_literals -from rasa_core_sdk import Tracker -from rasa_core_sdk.events import ActionExecuted, UserUttered +from rasa_sdk import Tracker +from rasa_sdk.events import ActionExecuted, UserUttered def test_latest_input_channel():