def _assert_two_stage_fallback_policy_is_migratable(config: Dict) -> None: two_stage_fallback_config = next( (policy_config for policy_config in config.get("policies", []) if policy_config.get("name") == TwoStageFallbackPolicy.__name__), None, ) if not two_stage_fallback_config: return if (two_stage_fallback_config.get("deny_suggestion_intent_name", USER_INTENT_OUT_OF_SCOPE) != USER_INTENT_OUT_OF_SCOPE): rasa.shared.utils.cli.print_error_and_exit( f"The TwoStageFallback in Rasa Open Source 2.0 has to use the intent " f"'{USER_INTENT_OUT_OF_SCOPE}' to recognize when users deny suggestions. " f"Please change the parameter 'deny_suggestion_intent_name' to " f"'{USER_INTENT_OUT_OF_SCOPE}' before migrating the model configuration. " ) if (two_stage_fallback_config.get("fallback_nlu_action_name", ACTION_DEFAULT_FALLBACK_NAME) != ACTION_DEFAULT_FALLBACK_NAME): rasa.shared.utils.cli.print_error_and_exit( f"The Two-Stage Fallback in Rasa Open Source 2.0 has to use the action " f"'{ACTION_DEFAULT_FALLBACK_NAME}' for cases when the user denies the " f"suggestion multiple times. " f"Please change the parameter 'fallback_nlu_action_name' to " f"'{ACTION_DEFAULT_FALLBACK_NAME}' before migrating the model " f"configuration. ")
def _assert_nlu_pipeline_given(config: Dict, policy_names: List[Text]) -> None: if not config.get("pipeline") and any( policy in policy_names for policy in [FallbackPolicy.__name__, TwoStageFallbackPolicy.__name__]): rasa.shared.utils.cli.print_error_and_exit( "The model configuration has to include an NLU pipeline. This is required " "in order to migrate the fallback policies.")
def _assert_nlu_pipeline_given(config: Dict, policy_names: List[Text]) -> None: if not config.get("pipeline") and any( policy in policy_names for policy in [POLICY_NAME_FALLBACK, POLICY_NAME_TWO_STAGE_FALLBACK]): rasa.shared.utils.cli.print_error_and_exit( "The model configuration has to include an NLU pipeline. This is required " "in order to migrate the fallback policies.")
def _get_configuration(path: Path) -> Dict: config = {} try: config = rasa.shared.utils.io.read_config_file(path) except Exception: rasa.shared.utils.cli.print_error_and_exit( f"'{path}' is not a path to a valid model configuration. " f"Please provide a valid path.") policy_names = [p.get("name") for p in config.get("policies", [])] _assert_config_needs_migration(policy_names) _assert_nlu_pipeline_given(config, policy_names) _assert_two_stage_fallback_policy_is_migratable(config) _assert_only_one_fallback_policy_present(policy_names) if FormPolicy.__name__ in policy_names: _warn_about_manual_forms_migration() return config