def load_component(self, component_meta: Dict[Text, Any], model_dir: Text, model_metadata: "Metadata", **context: Any) -> Component: """Tries to retrieve a component from the cache, else calls ``load`` to create a new component. Args: component_meta: the metadata of the component to load in the pipeline model_dir: the directory to read the model from model_metadata (Metadata): the model's :class:`rasa.nlu.model.Metadata` Returns: Component: the loaded component. """ from rasa.nlu import registry try: cached_component, cache_key = self.__get_cached_component( component_meta, model_metadata) component = registry.load_component_by_meta( component_meta, model_dir, model_metadata, cached_component, **context) if not cached_component: # If the component wasn't in the cache, # let us add it if possible self.__add_to_cache(component, cache_key) return component except MissingArgumentError as e: # pragma: no cover raise Exception("Failed to load component from file `{}`. " "{}".format(component_meta.get("file"), e))
def load_component( self, component_meta: Dict[Text, Any], model_dir: Text, model_metadata: "Metadata", **context: Any, ) -> Optional[Component]: """Loads a component. Tries to retrieve a component from the cache, else calls ``load`` to create a new component. Args: component_meta: The metadata of the component to load in the pipeline. model_dir: The directory to read the model from. model_metadata (Metadata): The model's :class:`rasa.nlu.model.Metadata`. Returns: The loaded component. """ from rasa.nlu import registry try: cached_component, cache_key = self.__get_cached_component( component_meta, model_metadata) component = registry.load_component_by_meta( component_meta, model_dir, model_metadata, cached_component, **context) if not cached_component: # If the component wasn't in the cache, # let us add it if possible self.__add_to_cache(component, cache_key) return component except MissingArgumentError as e: # pragma: no cover raise RasaException( f"Failed to load component from file '{component_meta.get('file')}'. " f"Error: {e}")