コード例 #1
0
ファイル: registry.py プロジェクト: yurilq/rasa01
def policy_from_module_path(module_path: Text) -> Type["Policy"]:
    """Given the name of a policy module tries to retrieve the policy."""
    from rasa.core import utils

    try:
        return utils.class_from_module_path(module_path,
                                            lookup_path="rasa.core.policies")
    except ImportError:
        raise ImportError(
            "Cannot retrieve policy from path '{}'".format(module_path))
コード例 #2
0
ファイル: registry.py プロジェクト: yurilq/rasa01
def featurizer_from_module_path(
        module_path: Text) -> Type["TrackerFeaturizer"]:
    """Given the name of a featurizer module tries to retrieve it."""
    from rasa.core import utils

    try:
        return utils.class_from_module_path(
            module_path, lookup_path="rasa.core.featurizers")
    except ImportError:
        raise ImportError(
            "Cannot retrieve featurizer from path '{}'".format(module_path))
コード例 #3
0
ファイル: broker.py プロジェクト: kushal1212/Demo_Bot
def load_event_channel_from_module_string(
        broker_config: EndpointConfig) -> Optional["EventChannel"]:
    """Instantiate an event channel based on its class name."""

    try:
        event_channel = class_from_module_path(broker_config.type)
        return event_channel.from_endpoint_config(broker_config)
    except (AttributeError, ImportError) as e:
        logger.warning("EventChannel type '{}' not found. "
                       "Not using any event channel. Error: {}".format(
                           broker_config.type, e))
        return None
コード例 #4
0
 def resolve_by_type(type_name):
     """Returns a slots class by its type name."""
     for cls in utils.all_subclasses(Slot):
         if cls.type_name == type_name:
             return cls
     try:
         return utils.class_from_module_path(type_name)
     except (ImportError, AttributeError):
         raise ValueError(
             "Failed to find slot type, '{}' is neither a known type nor "
             "user-defined. If you are creating your own slot type, make "
             "sure its module path is correct.".format(type_name))
コード例 #5
0
    def load_tracker_from_module_string(domain, store):
        custom_tracker = None
        try:
            custom_tracker = class_from_module_path(store.type)
        except (AttributeError, ImportError):
            logger.warning("Store type '{}' not found. "
                           "Using InMemoryTrackerStore instead".format(
                               store.type))

        if custom_tracker:
            return custom_tracker(domain=domain, url=store.url, **store.kwargs)
        else:
            return InMemoryTrackerStore(domain)
コード例 #6
0
def _create_single_channel(channel, credentials):
    from rasa.core.channels import BUILTIN_CHANNELS

    if channel in BUILTIN_CHANNELS:
        return BUILTIN_CHANNELS[channel].from_credentials(credentials)
    else:
        # try to load channel based on class name
        try:
            input_channel_class = utils.class_from_module_path(channel)
            return input_channel_class.from_credentials(credentials)
        except (AttributeError, ImportError):
            raise Exception(
                "Failed to find input channel class for '{}'. Unknown "
                "input channel. Check your credentials configuration to "
                "make sure the mentioned channel is not misspelled. "
                "If you are creating your own channel, make sure it "
                "is a proper name of a class in a module.".format(channel))
コード例 #7
0
    def load(cls, path: Text) -> "PolicyEnsemble":
        """Loads policy and domain specification from storage"""

        metadata = cls.load_metadata(path)
        cls.ensure_model_compatibility(metadata)
        policies = []
        for i, policy_name in enumerate(metadata["policy_names"]):
            policy_cls = registry.policy_from_module_path(policy_name)
            dir_name = "policy_{}_{}".format(i, policy_cls.__name__)
            policy_path = os.path.join(path, dir_name)
            policy = policy_cls.load(policy_path)
            cls._ensure_loaded_policy(policy, policy_cls, policy_name)
            policies.append(policy)
        ensemble_cls = utils.class_from_module_path(metadata["ensemble_name"])
        fingerprints = metadata.get("action_fingerprints", {})
        ensemble = ensemble_cls(policies, fingerprints)
        return ensemble