def _persist_metadata( metadata: ModelMetadata, temporary_directory: Path, ) -> None: rasa.shared.utils.io.dump_obj_as_json_to_file( temporary_directory / MODEL_ARCHIVE_METADATA_FILE, metadata.as_dict())
def test_metadata_serialization(domain: Domain, tmp_path: Path): train_schema = GraphSchema({ "train": SchemaNode( needs={}, uses=PersistableTestComponent, fn="train", constructor_name="create", config={ "some_config": 123455, "some more config": [{ "nested": "hi" }] }, ), "load": SchemaNode( needs={"resource": "train"}, uses=PersistableTestComponent, fn="run_inference", constructor_name="load", config={}, is_target=True, ), }) predict_schema = GraphSchema({ "run": SchemaNode( needs={}, uses=PersistableTestComponent, fn="run", constructor_name="load", config={ "some_config": 123455, "some more config": [{ "nested": "hi" }] }, ), }) trained_at = datetime.utcnow() rasa_version = rasa.__version__ model_id = "some unique model id" metadata = ModelMetadata( trained_at, rasa_version, model_id, domain, train_schema, predict_schema, project_fingerprint="some_fingerprint", training_type=TrainingType.NLU, core_target="core", nlu_target="nlu", language="zh", ) serialized = metadata.as_dict() # Dump and Load to make sure it's serializable dump_path = tmp_path / "metadata.json" rasa.shared.utils.io.dump_obj_as_json_to_file(dump_path, serialized) loaded_serialized = rasa.shared.utils.io.read_json_file(dump_path) loaded_metadata = ModelMetadata.from_dict(loaded_serialized) assert loaded_metadata.domain.as_dict() == domain.as_dict() assert loaded_metadata.model_id == model_id assert loaded_metadata.rasa_open_source_version == rasa_version assert loaded_metadata.trained_at == trained_at assert loaded_metadata.train_schema == train_schema assert loaded_metadata.predict_schema == predict_schema assert loaded_metadata.project_fingerprint == "some_fingerprint" assert loaded_metadata.training_type == TrainingType.NLU assert loaded_metadata.core_target == "core" assert loaded_metadata.nlu_target == "nlu" assert loaded_metadata.language == "zh"