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

Commit

Permalink
Merge branch 'master' into local
Browse files Browse the repository at this point in the history
  • Loading branch information
ricwo committed Mar 7, 2019
2 parents 5124609 + 7377440 commit bca29e1
Show file tree
Hide file tree
Showing 30 changed files with 336 additions and 109 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*pyc
*~
.env
venv
.cache/
.pytest_cache/
.coverage
Expand Down
15 changes: 12 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,30 @@ Added
for tensorflow based pipelines
- open api spec for the Rasa Core SDK action server
- documentation about early deactivation of a form in validation
- Added max_event_history in tracker_store to set this value in DialogueStateTracker
- utility functions for colored logging
- open webbrowser when visualizing stories
- added ``/parse`` endpoint to query for NLU results
- File based event store
- ability to configure event store using the endpoints file
- added ability to use multiple env vars per line in yaml files
- added ``priority`` property of policies to influence best policy in
the case of equal confidence

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``
- changed export paths for interactive training to ``data/core/stories.md``,
``data/nlu/nlu.md`` and ``data/nlu/nlu_interactive.md``
- ``event_broker.publish`` receives the event as a dict instead of text
- configuration key ``store_type`` of the tracker store endpoint configuration
has been renamed to ``type`` to allow usage accross endpoints
has been renamed to ``type`` to allow usage across endpoints
- renamed ``policy_metadata.json`` to ``metadata.json`` for persisted models
- ``scores`` array returned by the ``/conversations/{sender_id}/predict``
endpoint is now sorted according to the actions' scores.
- changed payloads from "text" to "message" in files: server.yml, docs/connectors.rst,
rasa_core/server.py, rasa_core/training/interactive.py, tests/test_interactive.py

Removed
-------
Expand All @@ -46,6 +49,10 @@ Fixed
-----
- When a ``fork`` is used in interactive learning, every forked
storyline is saved (not just the last)
- Handles slot names which contain characters that are invalid as python
variable name (e.g. dot) in a template
- When a ``fork`` is used in interactive learning, every forked storyline
is saved (not just the last)

[0.13.2] - 2019-02-06
^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -88,6 +95,8 @@ Added
- SlackInput wont ignore ``app_mention`` event anymore.
Will handle messages containing @mentions to bots and will respond to these
(as long as the event itself is enabled in the application hosting the bot)
- Added sanitization mechanism for SlackInput that (in its current shape and form)
strips bot's self mentions from messages posted using the said @mentions.
- Added sanitization mechanism for SlackInput that (in its current
shape and form) strips bot's self mentions from messages posted using
the said @mentions.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2018 Rasa Technologies GmbH
Copyright 2019 Rasa Technologies GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ and apply your changes.

## License
Licensed under the Apache License, Version 2.0.
Copyright 2018 Rasa Technologies GmbH. [Copy of the license](LICENSE.txt).
Copyright 2019 Rasa 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
Expand Down
3 changes: 3 additions & 0 deletions data/test_endpoints/event_brokers/file_endpoint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
event_broker:
path: "rasa_event.log"
type: file
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ event_broker:
url: localhost
username: username
password: password
queue: queue
queue: queue
type: pika
36 changes: 36 additions & 0 deletions docs/_static/spec/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,42 @@ paths:
500:
$ref: '#/components/responses/500Action'

/parse:
post:
security:
- TokenAuth: []
- JWT: []
tags:
- Model
summary: Parse a message using the loaded NLU model
description: >-
Predicts the intent and entities of the message
posted to this endpoint. No messages will be stored
to a conversation and no action will be run. This will
just retrieve the NLU parse results.
operationId: parseNLU
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
q:
type: string
description: Message to be parsed
example:
q: "Hello, I am Rasa!"
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/ParseData'
403:
$ref: '#/components/responses/403Permissions'

/domain:
get:
security:
Expand Down
2 changes: 1 addition & 1 deletion docs/brokers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You can use an endpoint configuration file to instruct Rasa Core to stream
all events to your event broker. To do so, add the following section to your
endpoint configuration, e.g. ``endpoints.yml``:

.. literalinclude:: ../data/test_endpoints/event_broker_endpoint.yml
.. literalinclude:: ../data/test_endpoints/event_brokers/pika_endpoint.yml

Then instruct Rasa Core to use the endpoint configuration by adding
``--endpoints <path to your endpoint configuration`` when running it.
Expand Down
7 changes: 0 additions & 7 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
:desc: Rasa Core Changelog

.. include:: ../CHANGELOG.rst
Added
-------
- Added `priority` property of policies to influence best policy in the case of equal confidence

Changed
-------
- Change payloads from "text" to "message" in files: server.yml, docs/connectors.rst, rasa_core/server.py, rasa_core/training/interactive.py, tests/test_interactive.py
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

# General information about the project.
project = u'Rasa Core'
copyright = u'2018, Rasa Technologies GmbH'
copyright = u'2019, Rasa Technologies GmbH'
author = u'Rasa Technologies GmbH'

# The version info for the project you're documenting, acts as replacement for
Expand Down
2 changes: 1 addition & 1 deletion docs/connectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ you need to supply a ``credentials.yml`` with the following content:
slack:
slack_token: "xoxb-286425452756-safjasdf7sl38KLls"
slack_channel: "#my_channel"
slack_channel: "#my_channel" <!-- or "@my_app" -->
The endpoint for receiving slack messages is
Expand Down
14 changes: 7 additions & 7 deletions rasa_core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,21 @@ def _init_model_from_server(model_server: EndpointConfig
return fingerprint, model_directory


def _is_stack_model(model_directory: Text):
def _is_stack_model(model_directory: Text) -> bool:
"""Decide whether a persisted model is a stack or a core model."""

# TODO: find a better way to check this
return os.path.exists(os.path.join(model_directory, "rasa_model"))
return os.path.exists(os.path.join(model_directory, "fingerprint.json"))


def _load_and_set_updated_model(agent: 'Agent',
model_directory: Text,
fingerprint: Text):
"""Load the persisted model into memory and set the model on the agent."""

if _is_stack_model(model_directory):
from rasa_core.interpreter import RasaNLUInterpreter
nlu_model = os.path.join(model_directory, "rasa_model", "nlu")
core_model = os.path.join(model_directory, "rasa_model", "core")
nlu_model = os.path.join(model_directory, "nlu")
core_model = os.path.join(model_directory, "core")
interpreter = RasaNLUInterpreter(model_directory=nlu_model)
else:
interpreter = agent.interpreter
Expand Down Expand Up @@ -173,7 +173,7 @@ def _pull_model_and_fingerprint(model_server: EndpointConfig,
return None

utils.unarchive(response.content, model_directory)
logger.debug("Unzipped model to {}"
logger.debug("Unzipped model to '{}'"
"".format(os.path.abspath(model_directory)))

# get the new fingerprint
Expand Down Expand Up @@ -244,7 +244,7 @@ def update_model(self,
self.policy_ensemble = policy_ensemble

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

self._set_fingerprint(fingerprint)

Expand Down
52 changes: 27 additions & 25 deletions rasa_core/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,6 @@
logger = logging.getLogger(__name__)


def load_event_channel_from_module_string(broker_config: EndpointConfig
) -> Optional['EventChannel']:
"""Instantiate an event channel based on its class name."""

try:
event_channel = class_from_module_path(broker_config.type)
return event_channel.from_endpoint_config(broker_config)
except (AttributeError, ImportError):
logger.warning("EventChannel type {} not found. "
"Not using any event channel."
.format(broker_config.type))
return None


def from_endpoint_config(broker_config: Optional[EndpointConfig]
) -> Optional['EventChannel']:
"""Instantiate an event channel based on its configuration."""
Expand All @@ -36,6 +22,20 @@ def from_endpoint_config(broker_config: Optional[EndpointConfig]
return load_event_channel_from_module_string(broker_config)


def load_event_channel_from_module_string(broker_config: EndpointConfig
) -> Optional['EventChannel']:
"""Instantiate an event channel based on its class name."""

try:
event_channel = class_from_module_path(broker_config.type)
return event_channel.from_endpoint_config(broker_config)
except (AttributeError, ImportError) as e:
logger.warning("EventChannel type '{}' not found. "
"Not using any event channel. Error: {}"
.format(broker_config.type, e))
return None


class EventChannel(object):
@classmethod
def from_endpoint_config(cls, broker_config: EndpointConfig
Expand All @@ -62,7 +62,7 @@ def __init__(self, host, username, password,
self.credentials = pika.PlainCredentials(username, password)

@classmethod
def from_endpoint_config(cls, broker_config):
def from_endpoint_config(cls, broker_config) -> Optional['PikaProducer']:
if broker_config is None:
return None

Expand Down Expand Up @@ -98,34 +98,36 @@ class FileProducer(EventChannel):

DEFAULT_LOG_FILE_NAME = "rasa_event.log"

def __init__(self, path=None) -> None:
self.event_logger = self._event_logger(path)
def __init__(self, path: Optional[Text] = None) -> None:
self.path = path or self.DEFAULT_LOG_FILE_NAME
self.event_logger = self._event_logger()

@classmethod
def from_endpoint_config(cls, broker_config) -> Optional['FileProducer']:
def from_endpoint_config(cls, broker_config: Optional['EndpointConfig']
) -> Optional['FileProducer']:
if broker_config is None:
return None

# noinspection PyArgumentList
return cls(**broker_config.kwargs)

def _event_logger(self, file_name):
"""Instantiate the file logger"""
def _event_logger(self):
"""Instantiate the file logger."""

logger_file = file_name or self.DEFAULT_LOG_FILE_NAME
logger_file = self.path
# noinspection PyTypeChecker
query_logger = logging.getLogger('event-logger')
query_logger.setLevel(logging.INFO)
ch = logging.FileHandler(logger_file)
ch.setFormatter(logging.Formatter('%(message)s'))
handler = logging.FileHandler(logger_file)
handler.setFormatter(logging.Formatter('%(message)s'))
query_logger.propagate = False
query_logger.addHandler(ch)
query_logger.addHandler(handler)

logger.info("Logging events to '{}'.".format(logger_file))

return query_logger

def publish(self, event):
def publish(self, event: Dict) -> None:
"""Write event to file."""

self.event_logger.info(json.dumps(event))
Expand Down
2 changes: 1 addition & 1 deletion rasa_core/channels/rasa_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, url):
self.base_url = url

def _check_token(self, token):
url = "{}/users/me".format(self.base_url)
url = "{}/user".format(self.base_url)
headers = {"Authorization": token}
logger.debug("Requesting user information from auth server {}."
"".format(url))
Expand Down
Loading

0 comments on commit bca29e1

Please sign in to comment.