def _get_prediction( policy: Policy, tracker: DialogueStateTracker, domain: Domain, interpreter: NaturalLanguageInterpreter, ) -> Prediction: number_of_arguments_in_rasa_1_0 = 2 arguments = common_utils.arguments_of( policy.predict_action_probabilities) if (len(arguments) > number_of_arguments_in_rasa_1_0 and "interpreter" in arguments): probabilities = policy.predict_action_probabilities( tracker, domain, interpreter) else: common_utils.raise_warning( "The function `predict_action_probabilities` of " "the `Policy` interface was changed to support " "additional parameters. Please make sure to " "adapt your custom `Policy` implementation.", category=DeprecationWarning, ) probabilities = policy.predict_action_probabilities( tracker, domain) return Prediction(probabilities, policy.priority)
def minimal_kwargs( kwargs: Dict[Text, Any], func: Callable, excluded_keys: Optional[List] = None ) -> Dict[Text, Any]: """Returns only the kwargs which are required by a function. Keys, contained in the exception list, are not included. Args: kwargs: All available kwargs. func: The function which should be called. excluded_keys: Keys to exclude from the result. Returns: Subset of kwargs which are accepted by `func`. """ from rasa.utils.common import arguments_of excluded_keys = excluded_keys or [] possible_arguments = arguments_of(func) return { k: v for k, v in kwargs.items() if k in possible_arguments and k not in excluded_keys }
def conversation_id_from_args(args: Any, kwargs: Any) -> Optional[Text]: argnames = common_utils.arguments_of(f) try: sender_id_arg_idx = argnames.index("conversation_id") if "conversation_id" in kwargs: # try to fetch from kwargs first return kwargs["conversation_id"] if sender_id_arg_idx < len(args): return args[sender_id_arg_idx] return None except ValueError: return None
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.utils.common import arguments_of possible_arguments = arguments_of(func) return {k: v for k, v in kwargs.items() if k in possible_arguments}
def load_tracker_from_module_string( domain: Domain, store: EndpointConfig, event_broker: Optional[EventChannel] = None, ) -> "TrackerStore": """ Initializes a custom tracker. Args: domain: defines the universe in which the assistant operates store: the specific tracker store event_broker: an event broker to publish events Returns: custom_tracker: a tracker store from a specified database InMemoryTrackerStore: only used if no other tracker store is configured """ custom_tracker = None try: custom_tracker = common.class_from_module_path(store.type) except (AttributeError, ImportError): warnings.warn(f"Store type '{store.type}' not found. " f"Using InMemoryTrackerStore instead.") if custom_tracker: init_args = common.arguments_of(custom_tracker.__init__) if "url" in init_args and "host" not in init_args: warnings.warn( "The `url` initialization argument for custom tracker stores is deprecated. Your " "custom tracker store should take a `host` argument in ``__init__()`` instead.", FutureWarning, ) store.kwargs["url"] = store.url else: store.kwargs["host"] = store.url return custom_tracker( domain=domain, event_broker=event_broker, **store.kwargs, ) else: return InMemoryTrackerStore(domain)
def _load_from_module_name_in_endpoint_config( domain: Domain, store: EndpointConfig, event_broker: Optional[EventBroker] = None ) -> "TrackerStore": """Initializes a custom tracker. Defaults to the InMemoryTrackerStore if the module path can not be found. Args: domain: defines the universe in which the assistant operates store: the specific tracker store event_broker: an event broker to publish events Returns: a tracker store from a specified type in a stores endpoint configuration """ try: tracker_store_class = rasa.shared.utils.common.class_from_module_path( store.type ) init_args = common_utils.arguments_of(tracker_store_class.__init__) if "url" in init_args and "host" not in init_args: # DEPRECATION EXCEPTION - remove in 2.1 raise Exception( "The `url` initialization argument for custom tracker stores has " "been removed. Your custom tracker store should take a `host` " "argument in its `__init__()` instead." ) else: store.kwargs["host"] = store.url return tracker_store_class( domain=domain, event_broker=event_broker, **store.kwargs ) except (AttributeError, ImportError): rasa.shared.utils.io.raise_warning( f"Tracker store with type '{store.type}' not found. " f"Using `InMemoryTrackerStore` instead." ) return InMemoryTrackerStore(domain)
def _load_from_module_string( domain: Domain, store: EndpointConfig, event_broker: Optional[EventBroker] = None ) -> "TrackerStore": """Initializes a custom tracker. Defaults to the InMemoryTrackerStore if the module path can not be found. Args: domain: defines the universe in which the assistant operates store: the specific tracker store event_broker: an event broker to publish events Returns: a tracker store from a specified type in a stores endpoint configuration """ try: tracker_store_class = class_from_module_path(store.type) init_args = common.arguments_of(tracker_store_class.__init__) if "url" in init_args and "host" not in init_args: warnings.warn( "The `url` initialization argument for custom tracker stores is deprecated. Your " "custom tracker store should take a `host` argument in ``__init__()`` instead.", FutureWarning, ) store.kwargs["url"] = store.url else: store.kwargs["host"] = store.url return tracker_store_class( domain=domain, event_broker=event_broker, **store.kwargs ) except (AttributeError, ImportError): warnings.warn( f"Tracker store type '{store.type}' not found. " f"Using `InMemoryTrackerStore` instead." ) return InMemoryTrackerStore(domain)