Skip to content

Commit

Permalink
Merge eb066cb into 57c3632
Browse files Browse the repository at this point in the history
  • Loading branch information
btotharye committed Nov 18, 2019
2 parents 57c3632 + eb066cb commit 2583f8c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -21,6 +21,9 @@ Added

Changed
-------
- Print info message when running Rasa X and and custom model server url was specified in ``endpoints.yml``
- If a ``wait_time_between_pulls`` is configured for the model server in ``endpoints.yml``,
this will be used instead of the default one when running Rasa X
- Do not retrain the entire Core model if only the ``templates`` section of the domain is changed.
- Upgraded ``jsonschema`` version

Expand Down
18 changes: 16 additions & 2 deletions rasa/cli/x.py
Expand Up @@ -112,10 +112,24 @@ def _overwrite_endpoints_for_local_x(
from rasa.utils.endpoints import EndpointConfig
import questionary

# Checking if endpoint.yml has existing url and wait time values set, if so give warning we are overwriting
# the endpoint.yml file.
custom_wait_time_pulls = endpoints.model.kwargs.get("wait_time_between_pulls")
custom_url = endpoints.model.url
default_rasax_model_server_url = (
f"{rasa_x_url}/projects/default/models/tag/production"
)

if custom_url != default_rasax_model_server_url:
logger.info(
f"Ignoring url '{custom_url}' from 'endpoints.yml' and using "
f"'{default_rasax_model_server_url}' instead."
)

endpoints.model = EndpointConfig(
f"{rasa_x_url}/projects/default/models/tags/production",
default_rasax_model_server_url,
token=rasa_x_token,
wait_time_between_pulls=2,
wait_time_between_pulls=custom_wait_time_pulls or 2,
)

overwrite_existing_event_broker = False
Expand Down
40 changes: 40 additions & 0 deletions tests/cli/test_rasa_x.py
@@ -1,14 +1,19 @@
from pathlib import Path
import logging

import pytest
from typing import Callable, Dict
from _pytest.pytester import RunResult
from _pytest.logging import LogCaptureFixture


from aioresponses import aioresponses

import rasa.utils.io as io_utils
from rasa.cli import x
from rasa.utils.endpoints import EndpointConfig
from rasa.core.utils import AvailableEndpoints
from tests.conftest import assert_log_emitted


def test_x_help(run: Callable[..., RunResult]):
Expand Down Expand Up @@ -80,6 +85,41 @@ def test_if_endpoint_config_is_invalid_in_local_mode(kwargs: Dict):
assert not x._is_correct_event_broker(config)


def test_overwrite_for_local_x(caplog: LogCaptureFixture):
test_wait_time = 5
default_wait_time = 2
endpoint_config_missing_wait = EndpointConfig(
url="http://testserver:5002/models/default@latest"
)
endpoint_config_custom = EndpointConfig(
url="http://testserver:5002/models/default@latest",
wait_time_between_pulls=test_wait_time,
)
endpoints_custom = AvailableEndpoints(model=endpoint_config_custom)
endpoints_missing_wait = AvailableEndpoints(model=endpoint_config_missing_wait)

# Check that we get INFO message about overwriting the endpoints configuration
log_message = "Ignoring url 'http://testserver:5002/models/default@latest' from 'endpoints.yml' and using 'http://localhost/projects/default/models/tag/production' instead"
with assert_log_emitted(caplog, "rasa.cli.x", logging.INFO, log_message):
x._overwrite_endpoints_for_local_x(endpoints_custom, "test", "http://localhost")

# Checking for url to be changed in config and wait time value to be honored
assert (
endpoints_custom.model.url
== "http://localhost/projects/default/models/tag/production"
)
assert endpoints_custom.model.kwargs["wait_time_between_pulls"] == test_wait_time

# Check for wait time to be set to 3 since it isn't specified
x._overwrite_endpoints_for_local_x(
endpoints_missing_wait, "test", "http://localhost"
)
assert (
endpoints_missing_wait.model.kwargs["wait_time_between_pulls"]
== default_wait_time
)


async def test_pull_runtime_config_from_server():
config_url = "http://example.com/api/config?token=token"
credentials = "rasa: http://example.com:5002/api"
Expand Down

0 comments on commit 2583f8c

Please sign in to comment.