def is_metrics_collection_enabled(args: argparse.Namespace) -> bool: """Make sure the user consents to any metrics collection.""" try: allow_metrics = read_global_config_value("metrics", unavailable_ok=False) return allow_metrics.get("enabled", False) except ValueError: pass # swallow the error and ask the user allow_metrics = (questionary.confirm( "Rasa will track a minimal amount of anonymized usage information " "(like how often you use the 'train' button) to help us improve Rasa X. " "None of your training data or conversations will ever be sent to Rasa. " "Are you OK with Rasa collecting anonymized usage data?").skip_if( args.no_prompt, default=True).ask()) print_success("Your decision has been stored into {}. " "".format(GLOBAL_USER_CONFIG_PATH)) if not args.no_prompt: date = datetime.datetime.now() write_global_config_value("metrics", { "enabled": allow_metrics, "date": date }) return allow_metrics
def open_web_browser(login_url: Text) -> None: """Opens a new tab on the user's preferred web browser and points it to `login_url`. Depending on the telemetry configuration, a separate tab may be opened as well, showing the user a welcome page. Args: login_url: URL which the tab should be pointed at. """ import webbrowser telemetry_config = rasa_utils.read_global_config_value( constants.CONFIG_FILE_TELEMETRY_KEY) if telemetry_config and telemetry_config[ constants.CONFIG_TELEMETRY_ENABLED]: # If the telemetry config does not contain CONFIG_TELEMETRY_WELCOME_SHOWN, # then the user has upgraded from a previous version of Rasa X (before # this config value was introduced). In these cases, assume that the # user has already seen the welcome page. if not telemetry_config.get( constants.CONFIG_TELEMETRY_WELCOME_SHOWN, True): webbrowser.open_new_tab(constants.WELCOME_PAGE_URL) telemetry_config[constants.CONFIG_TELEMETRY_WELCOME_SHOWN] = True rasa_utils.write_global_config_value( constants.CONFIG_FILE_TELEMETRY_KEY, telemetry_config) webbrowser.open_new_tab(login_url)
def _write_default_telemetry_configuration( is_enabled: bool = TELEMETRY_ENABLED_BY_DEFAULT, ) -> None: if is_enabled: print_telemetry_reporting_info() new_config = _default_telemetry_configuration(is_enabled) rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, new_config)
def _write_default_telemetry_configuration( is_enabled: bool = TELEMETRY_ENABLED_BY_DEFAULT, ) -> None: if is_enabled and os.environ.get( TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE) is None: print_telemetry_reporting_info() new_config = _default_telemetry_configuration(is_enabled) rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, new_config)
def accept_terms_or_quit(args: argparse.Namespace) -> None: """Prompt the user to accept the Rasa terms.""" import webbrowser import questionary from rasax.community.constants import RASA_TERMS_URL show_prompt = not hasattr(args, "no_prompt") or not args.no_prompt if not show_prompt: print( f"By adding the '--no_prompt' parameter you agreed to the Rasa " f"X license agreement ({RASA_TERMS_URL})" ) return rasa_cli_utils.print_success( "Before you can use Rasa X, you have to agree to its " "license agreement (you will only have to do this " "once)." ) should_open_in_browser = questionary.confirm( "Would you like to view the license agreement in your web browser?" ).ask() if should_open_in_browser: webbrowser.open(RASA_TERMS_URL) accepted_terms = questionary.confirm( "\nRasa X License Agreement\n" "===========================\n\n" "Do you agree to the Rasa X license agreement ({})?\n" "By typing 'y', you agree to the terms. " "If you are using this software for a company, by confirming, " "you acknowledge you have the authority to do so.\n" "If you do not agree, type 'n' to stop Rasa X." "".format(RASA_TERMS_URL), default=False, qmark="", ).ask() if accepted_terms: rasa_utils.write_global_config_value(CONFIG_FILE_TERMS_KEY, True) else: rasa_cli_utils.print_error_and_exit( "Sorry, without accepting the terms, you cannot use Rasa X. " "You can of course still use the (Apache 2 licensed) Rasa framework: " "https://github.com/RasaHQ/rasa", exit_code=0, )
def toggle_telemetry_reporting(is_enabled: bool) -> None: """Write to the configuration if telemetry tracking should be enabled or disabled. Args: is_enabled: `True` if the telemetry reporting should be enabled, `False` otherwise. """ configuration = rasa_utils.read_global_config_value(CONFIG_FILE_TELEMETRY_KEY) if configuration: configuration[CONFIG_TELEMETRY_ENABLED] = is_enabled else: configuration = _default_telemetry_configuration(is_enabled) rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, configuration)
def initialize_from_file(no_prompt: bool) -> Optional["Process"]: """Read telemetry configuration from the user's Rasa config file in $HOME. After that is done, start consuming the telemetry events queue from a different process, if telemetry is enabled. Args: no_prompt: If `True`, do not prompt the user for input. """ if not config.LOCAL_MODE: logger.error( "Attempted to read telemetry configuration file in $HOME while in server " "mode. Telemetry will not be enabled.") return if not config.telemetry_write_key: # If the Segment write key has not been set via environment variable, # try to read it from the key file: config.telemetry_write_key = _read_segment_write_key() telemetry_enabled = None try: stored_config = rasa_utils.read_global_config_value( CONFIG_FILE_TELEMETRY_KEY, unavailable_ok=False) telemetry_enabled = stored_config[CONFIG_TELEMETRY_ENABLED] except ValueError as e: logger.debug( f"Could not read telemetry settings from configuration file: {e}") if telemetry_enabled is None: telemetry_enabled = _read_telemetry_consent(no_prompt) new_config = { CONFIG_TELEMETRY_ENABLED: telemetry_enabled, CONFIG_TELEMETRY_ID: uuid.uuid4().hex, CONFIG_TELEMETRY_DATE: datetime.datetime.now(), CONFIG_TELEMETRY_WELCOME_SHOWN: False, } rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, new_config) return _initialize_telemetry_process() if telemetry_enabled else None
def _write_default_telemetry_configuration( is_enabled: bool = TELEMETRY_ENABLED_BY_DEFAULT, ) -> bool: new_config = _default_telemetry_configuration(is_enabled) success = rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, new_config) if is_enabled and success: print_telemetry_reporting_info() return success
def _write_default_telemetry_configuration( is_enabled: bool = TELEMETRY_ENABLED_BY_DEFAULT, ) -> bool: new_config = _default_telemetry_configuration(is_enabled) success = rasa_utils.write_global_config_value(CONFIG_FILE_TELEMETRY_KEY, new_config) # Do not show info if user has enabled/disabled telemetry via env var telemetry_environ = os.environ.get(TELEMETRY_ENABLED_ENVIRONMENT_VARIABLE) if is_enabled and success and telemetry_environ is None: print_telemetry_reporting_info() return success