def validate_requirements(component_names): # type: (List[Text]) -> None """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry import importlib # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) for package in component_class.required_packages(): try: importlib.import_module(package) except ImportError: failed_imports.add(package) if failed_imports: # if available, use the development file to figure out the correct version numbers for each requirement if os.path.exists("dev-requirements.txt"): all_requirements = __read_dev_requirements("dev-requirements.txt") missing_requirements = [ r for i in failed_imports for r in all_requirements[i] ] raise Exception( "Not all required packages are installed. To use this pipeline, run\n\t" + "> pip install {}".format(" ".join(missing_requirements))) else: raise Exception( "Not all required packages are installed. Please install {}". format(" ".join(failed_imports)))
def validate_requirements(component_names, dev_requirements_file="dev-requirements.txt"): # type: (List[Text], Text) -> None """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) failed_imports.update( find_unavailable_packages(component_class.required_packages())) if failed_imports: # pragma: no cover # if available, use the development file to figure out the correct version numbers for each requirement if os.path.exists(dev_requirements_file): all_requirements = _read_dev_requirements(dev_requirements_file) missing_requirements = [ r for i in failed_imports for r in all_requirements[i] ] raise Exception( "Not all required packages are installed. To use this pipeline, run\n\t" + "> pip install {}".format(" ".join(missing_requirements))) else: raise Exception( "Not all required packages are installed. Please install {}". format(" ".join(failed_imports)))
def validate_requirements( component_names, dev_requirements_file="alt_requirements/requirements_dev.txt"): # type: (List[Text], Text) -> None """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) failed_imports.update( find_unavailable_packages(component_class.required_packages())) if failed_imports: # pragma: no cover # if available, use the development file to figure out the correct version numbers for each requirement all_requirements = _read_dev_requirements(dev_requirements_file) if all_requirements: missing_requirements = [ r for i in failed_imports for r in all_requirements[i] ] raise Exception( "Not all required packages are installed. " + "Failed to find the following imports {}. ".format(", ".join( failed_imports)) + "To use this pipeline, you need to install the missing dependencies, e.g. by running:\n\t" + "> pip install {}".format(" ".join(missing_requirements))) else: raise Exception( "Not all required packages are installed. " + "To use this pipeline, you need to install the missing dependencies. " + "Please install {}".format(", ".join(failed_imports)))
def __get_component(self, component_name, meta, context, model_config): component_class = registry.get_component_class(component_name) cache_key = component_class.cache_key(meta) if cache_key is not None and self.use_cache and cache_key in self.component_cache: component = self.component_cache[cache_key] else: component = registry.load_component_by_name(component_name, context, model_config) if cache_key is not None and self.use_cache: self.component_cache[cache_key] = component return component
def __get_cached_component(self, component_name, model_metadata): # type: (Text, Metadata) -> Tuple[Optional[Component], Optional[Text]] """Load a component from the cache, if it exists. Returns the component, if found, and the cache key.""" from rasa_nlu import registry from rasa_nlu.model import Metadata component_class = registry.get_component_class(component_name) cache_key = component_class.cache_key(model_metadata) if cache_key is not None and self.use_cache and cache_key in self.component_cache: return self.component_cache[cache_key], cache_key else: return None, cache_key
def __get_cached_component(self, component_name, model_metadata): # type: (Text, Metadata) -> Tuple[Optional[Component], Optional[Text]] """Load a component from the cache, if it exists. Returns the component, if found, and the cache key.""" from rasa_nlu import registry from rasa_nlu.model import Metadata component_class = registry.get_component_class(component_name) cache_key = component_class.cache_key(model_metadata) if cache_key is not None and self.use_cache and cache_key in self.component_cache: return self.component_cache[cache_key], cache_key else: return None, cache_key
def validate_requirements( component_names, dev_requirements_file="alt_requirements/requirements_dev.txt"): # type: (List[Text], Text) -> None """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) failed_imports.update( find_unavailable_packages(component_class.required_packages()))
def __get_cached_component(self, component_name, metadata): # type: (Text, Metadata) -> Tuple[Optional[Component], Optional[Text]] """Load a component from the cache, if it exists. Returns the component, if found, and the cache key.""" from rasa_nlu import registry from rasa_nlu.model import Metadata component_class = registry.get_component_class(component_name) if component_class is None: raise Exception("Failed to find component class for '{}'. Unknown component name.".format(component_name)) cache_key = component_class.cache_key(metadata) if cache_key is not None and self.use_cache and cache_key in self.component_cache: return self.component_cache[cache_key], cache_key else: return None, cache_key
def __init__(self, config): from rasa_nlu.registry import get_component_class self.config = config self.training_data = None self.pipeline = [] # Transform the passed names of the pipeline components into classes for component_name in config.pipeline: component_class = get_component_class(component_name) if component_class is not None: self.pipeline.append(component_class()) else: raise Exception( "Unregistered component '{}'. Failed to start trainer.". format(component_name))
def validate_requirements(component_names: List[Text]) -> None: """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) failed_imports.update( find_unavailable_packages(component_class.required_packages())) if failed_imports: # pragma: no cover # if available, use the development file to figure out the correct # version numbers for each requirement raise Exception("Not all required packages are installed. " + "To use this pipeline, you need to install the " "missing dependencies. " + "Please install {}".format(", ".join(failed_imports)))
def __get_cached_component( self, component_meta: Dict[Text, Any], model_metadata: 'Metadata' ) -> Tuple[Optional[Component], Optional[Text]]: """Load a component from the cache, if it exists. Returns the component, if found, and the cache key. """ from rasa_nlu import registry # try to get class name first, else create by name component_name = component_meta.get('class', component_meta['name']) component_class = registry.get_component_class(component_name) cache_key = component_class.cache_key(component_meta, model_metadata) if (cache_key is not None and self.use_cache and cache_key in self.component_cache): return self.component_cache[cache_key], cache_key else: return None, cache_key
def validate_requirements(component_names: List[Text]) -> None: """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) failed_imports.update(find_unavailable_packages( component_class.required_packages())) if failed_imports: # pragma: no cover # if available, use the development file to figure out the correct # version numbers for each requirement raise Exception("Not all required packages are installed. " + "To use this pipeline, you need to install the " "missing dependencies. " + "Please install {}".format(", ".join(failed_imports)))
def __get_cached_component(self, component_meta: Dict[Text, Any], model_metadata: 'Metadata' ) -> Tuple[Optional[Component], Optional[Text]]: """Load a component from the cache, if it exists. Returns the component, if found, and the cache key. """ from rasa_nlu import registry # try to get class name first, else create by name component_name = component_meta.get('class', component_meta['name']) component_class = registry.get_component_class(component_name) cache_key = component_class.cache_key(component_meta, model_metadata) if (cache_key is not None and self.use_cache and cache_key in self.component_cache): return self.component_cache[cache_key], cache_key else: return None, cache_key
def validate_requirements(component_names, dev_requirements_file="alt_requirements/requirements_dev.txt"): # type: (List[Text], Text) -> None """Ensures that all required python packages are installed to instantiate and used the passed components.""" from rasa_nlu import registry # Validate that all required packages are installed failed_imports = set() for component_name in component_names: component_class = registry.get_component_class(component_name) failed_imports.update(find_unavailable_packages(component_class.required_packages())) if failed_imports: # pragma: no cover # if available, use the development file to figure out the correct version numbers for each requirement all_requirements = _read_dev_requirements(dev_requirements_file) if all_requirements: missing_requirements = [r for i in failed_imports for r in all_requirements[i]] raise Exception("Not all required packages are installed. " + "Failed to find the following imports {}. ".format(", ".join(failed_imports)) + "To use this pipeline, you need to install the missing dependencies, e.g. by running:\n\t" + "> pip install {}".format(" ".join(missing_requirements))) else: raise Exception("Not all required packages are installed. " + "To use this pipeline, you need to install the missing dependencies. " + "Please install {}".format(", ".join(failed_imports)))