def separate_intent_response_key( original_intent: Text, ) -> Tuple[Text, Optional[Text]]: split_title = original_intent.split(RESPONSE_IDENTIFIER_DELIMITER) if len(split_title) == 2: return split_title[0], split_title[1] elif len(split_title) == 1: return split_title[0], None raise RasaException( f"Intent name '{original_intent}' is invalid, " f"it cannot contain more than one '{RESPONSE_IDENTIFIER_DELIMITER}'." )
def _validate_model_files_exist(model_directory: Text) -> None: """Check if essential model files exist inside the model_directory. Args: model_directory: Directory to investigate """ files_to_check = [ os.path.join(model_directory, "saved_model.pb"), os.path.join(model_directory, "variables/variables.index"), os.path.join(model_directory, "variables/variables.data-00001-of-00002"), os.path.join(model_directory, "variables/variables.data-00000-of-00002"), ] for file_path in files_to_check: if not os.path.exists(file_path): raise RasaException( f"""File {file_path} does not exist. Re-check the files inside the directory {model_directory}. It should contain the following model files - [{", ".join(files_to_check)}]""" )
def _get_validated_model_url(self) -> Text: """Validates the specified `model_url` parameter. The `model_url` parameter cannot be left empty. It can either be set to a remote URL where the model is hosted or it can be a path to a local directory. Returns: Validated path to model """ model_url = self.component_config.get("model_url", None) if not model_url: raise RasaException( f"Parameter 'model_url' was not specified in the configuration " f"of '{ConveRTFeaturizer.__name__}'. " f"It is mandatory to pass a value for this parameter. " f"You can either use a community hosted URL of the model " f"or if you have a local copy of the model, pass the " f"path to the directory containing the model files.") if model_url == ORIGINAL_TF_HUB_MODULE_URL: # Can't use the originally hosted URL raise RasaException( f"Parameter 'model_url' of '{ConveRTFeaturizer.__name__}' was " f"set to '{model_url}' which does not contain the model any longer. " f"You can either use a community hosted URL or if you have a " f"local copy of the model, pass the path to the directory " f"containing the model files.") if model_url == RESTRICTED_ACCESS_URL: # Can't use the URL that is reserved for tests only raise RasaException( f"Parameter 'model_url' of '{ConveRTFeaturizer.__name__}' was " f"set to '{model_url}' which is strictly reserved for pytests of " f"Rasa Open Source only. Due to licensing issues you are " f"not allowed to use the model from this URL. " f"You can either use a community hosted URL or if you have a " f"local copy of the model, pass the path to the directory " f"containing the model files.") if os.path.isfile(model_url): # Definitely invalid since the specified path should be a directory raise RasaException( f"Parameter 'model_url' of '{ConveRTFeaturizer.__name__}' was " f"set to the path of a file which is invalid. You " f"can either use a community hosted URL or if you have a " f"local copy of the model, pass the path to the directory " f"containing the model files.") if rasa.nlu.utils.is_url(model_url): return model_url if os.path.isdir(model_url): # Looks like a local directory. Inspect the directory # to see if model files exist. self._validate_model_files_exist(model_url) # Convert the path to an absolute one since # TFHUB doesn't like relative paths return os.path.abspath(model_url) raise RasaException( f"{model_url} is neither a valid remote URL nor a local directory. " f"You can either use a community hosted URL or if you have a " f"local copy of the model, pass the path to " f"the directory containing the model files.")