예제 #1
0
파일: server.py 프로젝트: zuiwanting/rasa
def _validate_json_training_payload(rjs: Dict):
    if "config" not in rjs:
        raise ErrorResponse(
            400,
            "BadRequest",
            "The training request is missing the required key `config`.",
            {"parameter": "config", "in": "body"},
        )

    if "nlu" not in rjs and "stories" not in rjs:
        raise ErrorResponse(
            400,
            "BadRequest",
            "To train a Rasa model you need to specify at least one type of "
            "training data. Add `nlu` and/or `stories` to the request.",
            {"parameters": ["nlu", "stories"], "in": "body"},
        )

    if "stories" in rjs and "domain" not in rjs:
        raise ErrorResponse(
            400,
            "BadRequest",
            "To train a Rasa model with story training data, you also need to "
            "specify the `domain`.",
            {"parameter": "domain", "in": "body"},
        )

    if "force" in rjs or "save_to_default_model_directory" in rjs:
        common_utils.raise_deprecation_warning(
            "Specifying 'force' and 'save_to_default_model_directory' as part of the "
            "JSON payload is deprecated. Please use the header arguments "
            "'force_training' and 'save_to_default_model_directory'.",
            docs=_docs("/api/http-api"),
        )
예제 #2
0
    def __init__(
        self,
        priority: int = FALLBACK_POLICY_PRIORITY,
        nlu_threshold: float = 0.3,
        ambiguity_threshold: float = 0.1,
        core_threshold: float = 0.3,
        fallback_action_name: Text = ACTION_DEFAULT_FALLBACK_NAME,
    ) -> None:
        """Create a new Fallback policy.

        Args:
            core_threshold: if NLU confidence threshold is met,
                predict fallback action with confidence `core_threshold`.
                If this is the highest confidence in the ensemble,
                the fallback action will be executed.
            nlu_threshold: minimum threshold for NLU confidence.
                If intent prediction confidence is lower than this,
                predict fallback action with confidence 1.0.
            ambiguity_threshold: threshold for minimum difference
                between confidences of the top two predictions
            fallback_action_name: name of the action to execute as a fallback
        """
        super().__init__(priority=priority)

        self.nlu_threshold = nlu_threshold
        self.ambiguity_threshold = ambiguity_threshold
        self.core_threshold = core_threshold
        self.fallback_action_name = fallback_action_name

        common_utils.raise_deprecation_warning(
            f"'{self.__class__.__name__}' is deprecated and will be removed "
            "in the future. It is recommended to use the 'RulePolicy' instead.",
            docs=DOCS_URL_MIGRATION_GUIDE,
        )
예제 #3
0
def _replace_deprecated_option(
    old_option: Text,
    new_option: Union[Text, List[Text]],
    config: Dict[Text, Any],
    warn_until_version: Text = NEXT_MAJOR_VERSION_FOR_DEPRECATIONS,
) -> Dict[Text, Any]:
    if old_option in config:
        if isinstance(new_option, str):
            common_utils.raise_deprecation_warning(
                f"Option '{old_option}' got renamed to '{new_option}'. "
                f"Please update your configuration file.",
                warn_until_version=warn_until_version,
            )
            config[new_option] = config[old_option]
        else:
            common_utils.raise_deprecation_warning(
                f"Option '{old_option}' got renamed to "
                f"a dictionary '{new_option[0]}' with a key '{new_option[1]}'. "
                f"Please update your configuration file.",
                warn_until_version=warn_until_version,
            )
            option_dict = config.get(new_option[0], {})
            option_dict[new_option[1]] = config[old_option]
            config[new_option[0]] = option_dict

    return config
예제 #4
0
def test_raise_deprecation_warning_default():
    with pytest.warns(FutureWarning) as record:
        raise_deprecation_warning("This feature is deprecated.")

    assert len(record) == 1
    assert record[0].message.args[0] == (
        f"This feature is deprecated. "
        f"(will be removed in {NEXT_MAJOR_VERSION_FOR_DEPRECATIONS})")
예제 #5
0
def test_raise_deprecation_warning():
    with pytest.warns(FutureWarning) as record:
        raise_deprecation_warning("This feature is deprecated.",
                                  warn_until_version="3.0.0")

    assert len(record) == 1
    assert (record[0].message.args[0] ==
            "This feature is deprecated. (will be removed in 3.0.0)")
예제 #6
0
    def __init__(self, priority: int = MAPPING_POLICY_PRIORITY) -> None:
        """Create a new Mapping policy."""

        super().__init__(priority=priority)

        common_utils.raise_deprecation_warning(
            f"'{MappingPolicy.__name__}' is deprecated and will be removed in "
            "the future. It is recommended to use the 'RulePolicy' instead.",
            docs=DOCS_URL_MIGRATION_GUIDE,
        )
예제 #7
0
def test_raise_deprecation_warning_version_already_in_message():
    with pytest.warns(FutureWarning) as record:
        raise_deprecation_warning(
            "This feature is deprecated and will be removed in 3.0.0!",
            warn_until_version="3.0.0",
        )

    assert len(record) == 1
    assert (record[0].message.args[0] ==
            "This feature is deprecated and will be removed in 3.0.0!")
예제 #8
0
    def _deserialise_dialogue_from_pickle(
        sender_id: Text, serialised_tracker: bytes
    ) -> Dialogue:

        common_utils.raise_deprecation_warning(
            f"Found pickled tracker for "
            f"conversation ID '{sender_id}'. Deserialisation of pickled "
            f"trackers is deprecated. Rasa will perform any "
            f"future save operations of this tracker using json serialisation.",
        )
        return pickle.loads(serialised_tracker)
예제 #9
0
    def __init__(
        self,
        featurizer: Optional[TrackerFeaturizer] = None,
        priority: int = FORM_POLICY_PRIORITY,
        lookup: Optional[Dict] = None,
    ) -> None:

        # max history is set to 2 in order to capture
        # previous meaningful action before action listen
        super().__init__(featurizer=featurizer,
                         priority=priority,
                         max_history=2,
                         lookup=lookup)

        common_utils.raise_deprecation_warning(
            f"'{FormPolicy.__name__}' is deprecated and will be removed in "
            "in the future. It is recommended to use the 'RulePolicy' instead.",
            docs=DOCS_URL_MIGRATION_GUIDE,
        )
예제 #10
0
    def from_credentials(cls, credentials: Optional[Dict[Text, Any]]) -> InputChannel:
        if credentials is None:
            cls.raise_missing_credentials_exception()

        # pytype: disable=attribute-error
        if credentials.get("pw") is not None or credentials.get("user") is not None:
            common_utils.raise_deprecation_warning(
                "Mattermost recently switched to bot accounts. 'user' and 'pw' "
                "should not be used anymore, you should rather convert your "
                "account to a bot account and use a token. Password based "
                "authentication will be removed in a future Rasa Open Source version.",
                docs=DOCS_URL_CONNECTORS + "mattermost/",
            )
            token = MattermostBot.token_from_login(
                credentials.get("url"), credentials.get("user"), credentials.get("pw")
            )
        else:
            token = credentials.get("token")

        return cls(credentials.get("url"), token, credentials.get("webhook_url"))