def recipe_for_name(name: Optional[Text]) -> Recipe: """Returns `Recipe` based on an optional recipe identifier. Args: name: The identifier which is used to select a certain `Recipe`. If `None` the default recipe will be used. Returns: A recipe which can be used to convert a given config to train and predict graph schemas. """ from rasa.engine.recipes.default_recipe import DefaultV1Recipe from rasa.engine.recipes.graph_recipe import GraphV1Recipe if name is None: rasa.shared.utils.io.raise_deprecation_warning( "From Rasa Open Source 4.0.0 onwards it will be required to specify " "a recipe in your model configuration. Defaulting to recipe " f"'{DefaultV1Recipe.name}'." ) return DefaultV1Recipe() recipes = { DefaultV1Recipe.name: DefaultV1Recipe, GraphV1Recipe.name: GraphV1Recipe, } recipe_constructor = recipes.get(name) if recipe_constructor: return recipe_constructor() raise InvalidRecipeException( f"No recipe with name '{name}' was found. " f"Available recipes are: " f"'{DefaultV1Recipe.name}'." )
def test_train_core_without_nlu_pipeline(): with pytest.raises(InvalidConfigException): DefaultV1Recipe().graph_config_for_recipe( {"policies": []}, {}, TrainingType.CORE, )
def test_retrieve_via_invalid_module_path(): with pytest.raises(ImportError): path = "rasa.core.policies.ted_policy.TEDPolicy1000" DefaultV1Recipe().graph_config_for_recipe( {"policies": [{ "name": path }]}, {}, TrainingType.CORE)
def test_no_warnings_with_default_project(tmp_path: Path): rasa.utils.common.copy_directory(Path("rasa/cli/initial_project"), tmp_path) importer = TrainingDataImporter.load_from_config( config_path=str(tmp_path / "config.yml"), domain_path=str(tmp_path / "domain.yml"), training_data_paths=[str(tmp_path / "data")], ) config, _missing_keys, _configured_keys = DefaultV1Recipe.auto_configure( importer.get_config_file_for_auto_config(), importer.get_config(), TrainingType.END_TO_END, ) graph_config = DefaultV1Recipe().graph_config_for_recipe( config, cli_parameters={}, training_type=TrainingType.END_TO_END) validator = DefaultV1RecipeValidator(graph_config.train_schema) with pytest.warns( UserWarning, match="Slot auto-fill has been removed in 3.0") as records: validator.validate(importer) assert all([ warn.message.args[0].startswith("Slot auto-fill has been removed") for warn in records.list ])
def test_nlu_do_not_raise_if_trainable_tokenizer(): config = rasa.shared.utils.io.read_yaml_file( "data/test_config/config_pretrained_embeddings_mitie_zh.yml") graph_config = DefaultV1Recipe().graph_config_for_recipe(config, cli_parameters={}) importer = DummyImporter() validator = DefaultV1RecipeValidator(graph_config.train_schema) # Does not raise validator.validate(importer)
def test_nlu_do_not_raise_if_two_tokenizers_with_end_to_end(): config = rasa.shared.utils.io.read_yaml_file( "rasa/engine/recipes/config_files/default_config.yml") graph_config = DefaultV1Recipe().graph_config_for_recipe( config, cli_parameters={}, training_type=TrainingType.END_TO_END) importer = DummyImporter() validator = DefaultV1RecipeValidator(graph_config.train_schema) # Does not raise validator.validate(importer)
def test_retrieve_via_module_path(): model_config = DefaultV1Recipe().graph_config_for_recipe( {"policies": [{ "name": "rasa.core.policies.ted_policy.TEDPolicy" }]}, {}, TrainingType.CORE, ) assert any( issubclass(node.uses, TEDPolicy) for node in model_config.train_schema.nodes.values()) assert any( issubclass(node.uses, TEDPolicy) for node in model_config.predict_schema.nodes.values())
def test_no_warnings_with_default_project(tmp_path: Path): rasa.utils.common.copy_directory(Path("rasa/cli/initial_project"), tmp_path) importer = TrainingDataImporter.load_from_config( config_path=str(tmp_path / "config.yml"), domain_path=str(tmp_path / "domain.yml"), training_data_paths=[str(tmp_path / "data")], ) config, _missing_keys, _configured_keys = DefaultV1Recipe.auto_configure( importer.get_config_file_for_auto_config(), importer.get_config(), TrainingType.END_TO_END, ) graph_config = DefaultV1Recipe().graph_config_for_recipe( config, cli_parameters={}, training_type=TrainingType.END_TO_END) validator = DefaultV1RecipeValidator(graph_config.train_schema) with pytest.warns(None) as records: validator.validate(importer) assert len(records) == 0