예제 #1
0
 def sender_id_from_args(args: Any, kwargs: Any) -> Optional[Text]:
     argnames = utils.arguments_of(f)
     try:
         sender_id_arg_idx = argnames.index("sender_id")
         if "sender_id" in kwargs:  # try to fetch from kwargs first
             return kwargs["sender_id"]
         if sender_id_arg_idx < len(args):
             return args[sender_id_arg_idx]
         return None
     except ValueError:
         return None
예제 #2
0
    def _get_valid_params(func: Callable, **kwargs: Any) -> Dict:
        # filter out kwargs that cannot be passed to func
        valid_keys = utils.arguments_of(func)

        params = {key: kwargs.get(key) for key in valid_keys if kwargs.get(key)}
        ignored_params = {
            key: kwargs.get(key) for key in kwargs.keys() if not params.get(key)
        }
        logger.debug(
            "Parameters ignored by `model.fit(...)`: {}".format(ignored_params)
        )
        return params
예제 #3
0
def minimal_kwargs(kwargs: Dict[Text, Any], func: Callable) -> Dict[Text, Any]:
    """Returns only the kwargs which are required by a function.

    Args:
        kwargs: All available kwargs.
        func: The function which should be called.

    Returns:
        Subset of kwargs which are accepted by `func`.

    """
    from rasa.core.utils import arguments_of

    possible_arguments = arguments_of(func)

    return {k: v for k, v in kwargs.items() if k in possible_arguments}