Example #1
0
async def test_events_schema(
    monkeypatch: MonkeyPatch, default_agent: Agent, config_path: Text
):
    # this allows us to patch the printing part used in debug mode to collect the
    # reported events
    monkeypatch.setenv("RASA_TELEMETRY_DEBUG", "true")
    monkeypatch.setenv("RASA_TELEMETRY_ENABLED", "true")

    mock = Mock()
    monkeypatch.setattr(telemetry, "print_telemetry_event", mock)

    with open(TELEMETRY_EVENTS_JSON) as f:
        schemas = json.load(f)["events"]
    initial = asyncio.all_tasks()
    # Generate all known backend telemetry events, and then use events.json to
    # validate their schema.
    training_data = TrainingDataImporter.load_from_config(config_path)

    with telemetry.track_model_training(training_data, "rasa"):
        await asyncio.sleep(1)

    telemetry.track_telemetry_disabled()

    telemetry.track_data_split(0.5, "nlu")

    telemetry.track_validate_files(True)

    telemetry.track_data_convert("yaml", "nlu")

    telemetry.track_tracker_export(5, TrackerStore(domain=None), EventBroker())

    telemetry.track_interactive_learning_start(True, False)

    telemetry.track_server_start([CmdlineInput()], None, None, 42, True)

    telemetry.track_project_init("tests/")

    telemetry.track_shell_started("nlu")

    telemetry.track_rasa_x_local()

    telemetry.track_visualization()

    telemetry.track_core_model_test(5, True, default_agent)

    telemetry.track_nlu_model_test(TrainingData())

    pending = asyncio.all_tasks() - initial
    await asyncio.gather(*pending)

    assert mock.call_count == 15

    for args, _ in mock.call_args_list:
        event = args[0]
        # `metrics_id` automatically gets added to all event but is
        # not part of the schema so we need to remove it before validation
        del event["properties"]["metrics_id"]
        jsonschema.validate(
            instance=event["properties"], schema=schemas[event["event"]]
        )
Example #2
0
File: x.py Project: spawn08/rasa
def run_locally(args: argparse.Namespace) -> None:
    """Run a Rasa X instance locally.

    Args:
        args: commandline arguments
    """
    _prevent_failure_if_git_is_not_available()

    try:
        # noinspection PyUnresolvedReferences
        from rasax.community import local
    except ModuleNotFoundError:
        raise MissingDependencyException(
            f"Rasa X does not seem to be installed, but it is needed for this "
            f"CLI command. You can find more information on how to install Rasa X "
            f"in local mode in the documentation: "
            f"{DOCS_BASE_URL_RASA_X}/installation-and-setup/install/local-mode"
        )

    args.rasa_x_port = args.rasa_x_port or DEFAULT_RASA_X_PORT
    args.port = args.port or DEFAULT_RASA_PORT

    project_path = "."

    _validate_rasa_x_start(args, project_path)

    rasa_x_token = generate_rasa_x_token()
    process = start_rasa_for_local_rasa_x(args, rasa_x_token=rasa_x_token)

    config_path = _get_config_path(args)
    domain_path = _get_domain_path(args)

    telemetry.track_rasa_x_local()

    # noinspection PyBroadException
    try:
        local.main(
            args,
            project_path,
            args.data,
            token=rasa_x_token,
            config_path=config_path,
            domain_path=domain_path,
        )
    except RasaXTermsError:
        # User didn't accept the Rasa X terms.
        pass
    except Exception:
        print(traceback.format_exc())
        rasa.shared.utils.cli.print_error(
            "Sorry, something went wrong (see error above). Make sure to start "
            "Rasa X with valid data and valid domain and config files. Please, "
            "also check any warnings that popped up.\nIf you need help fixing "
            "the issue visit our forum: https://forum.rasa.com/."
        )
    finally:
        process.terminate()
Example #3
0
File: x.py Project: alexlana/rasa-1
def run_locally(args: argparse.Namespace):
    # noinspection PyUnresolvedReferences
    from rasax.community import local  # pytype: disable=import-error

    args.rasa_x_port = args.rasa_x_port or DEFAULT_RASA_X_PORT
    args.port = args.port or DEFAULT_RASA_PORT

    project_path = "."

    _validate_rasa_x_start(args, project_path)

    rasa_x_token = generate_rasa_x_token()
    process = start_rasa_for_local_rasa_x(args, rasa_x_token=rasa_x_token)

    config_path = _get_config_path(args)

    telemetry.track_rasa_x_local()

    # noinspection PyBroadException
    try:
        local.main(
            args, project_path, args.data, token=rasa_x_token, config_path=config_path
        )
    except RasaXTermsError:
        # User didn't accept the Rasa X terms.
        pass
    except Exception:
        print(traceback.format_exc())
        rasa.shared.utils.cli.print_error(
            "Sorry, something went wrong (see error above). Make sure to start "
            "Rasa X with valid data and valid domain and config files. Please, "
            "also check any warnings that popped up.\nIf you need help fixing "
            "the issue visit our forum: https://forum.rasa.com/."
        )
    finally:
        process.terminate()