async def test_events_schema( monkeypatch: MonkeyPatch, default_agent: Agent, config_path: Text ): # this allows us to patch the printing part used in debug mode to collect the # reported events monkeypatch.setenv("RASA_TELEMETRY_DEBUG", "true") monkeypatch.setenv("RASA_TELEMETRY_ENABLED", "true") mock = Mock() monkeypatch.setattr(telemetry, "print_telemetry_event", mock) with open(TELEMETRY_EVENTS_JSON) as f: schemas = json.load(f)["events"] initial = asyncio.all_tasks() # Generate all known backend telemetry events, and then use events.json to # validate their schema. training_data = TrainingDataImporter.load_from_config(config_path) with telemetry.track_model_training(training_data, "rasa"): await asyncio.sleep(1) telemetry.track_telemetry_disabled() telemetry.track_data_split(0.5, "nlu") telemetry.track_validate_files(True) telemetry.track_data_convert("yaml", "nlu") telemetry.track_tracker_export(5, TrackerStore(domain=None), EventBroker()) telemetry.track_interactive_learning_start(True, False) telemetry.track_server_start([CmdlineInput()], None, None, 42, True) telemetry.track_project_init("tests/") telemetry.track_shell_started("nlu") telemetry.track_rasa_x_local() telemetry.track_visualization() telemetry.track_core_model_test(5, True, default_agent) telemetry.track_nlu_model_test(TrainingData()) pending = asyncio.all_tasks() - initial await asyncio.gather(*pending) assert mock.call_count == 15 for args, _ in mock.call_args_list: event = args[0] # `metrics_id` automatically gets added to all event but is # not part of the schema so we need to remove it before validation del event["properties"]["metrics_id"] jsonschema.validate( instance=event["properties"], schema=schemas[event["event"]] )
def visualize( domain_path: Text, stories_path: Text, nlu_data_path: Text, output_path: Text, max_history: int, ) -> None: """Visualizes stories as graph. Args: domain_path: Path to the domain file. stories_path: Path to the stories files. nlu_data_path: Path to the NLU training data which can be used to interpolate intents with actual examples in the graph. output_path: Path where the created graph should be persisted. max_history: Max history to use for the story visualization. """ import rasa.shared.core.training_data.visualization try: domain = Domain.load(domain_path) except InvalidDomain as e: print_error( f"Could not load domain due to: '{e}'. To specify a valid domain path use " f"the '--domain' argument.") return # this is optional, only needed if the `/greet` type of # messages in the stories should be replaced with actual # messages (e.g. `hello`) if nlu_data_path is not None: import rasa.shared.nlu.training_data.loading nlu_training_data = rasa.shared.nlu.training_data.loading.load_data( nlu_data_path) else: nlu_training_data = None logger.info("Starting to visualize stories...") telemetry.track_visualization() story_steps = loading.load_data_from_resource(stories_path, domain) rasa.shared.core.training_data.visualization.visualize_stories( story_steps, domain, output_path, max_history, nlu_training_data=nlu_training_data, ) full_output_path = "file://{}".format(os.path.abspath(output_path)) logger.info(f"Finished graph creation. Saved into {full_output_path}") import webbrowser webbrowser.open(full_output_path)
async def visualize( config_path: Text, domain_path: Text, stories_path: Text, nlu_data_path: Text, output_path: Text, max_history: int, ): from rasa.core.agent import Agent from rasa.core import config try: policies = config.load(config_path) except ValueError as e: print_error( "Could not load config due to: '{}'. To specify a valid config file use " "the '--config' argument.".format(e)) return try: agent = Agent(domain=domain_path, policies=policies) except InvalidDomain as e: print_error( "Could not load domain due to: '{}'. To specify a valid domain path use " "the '--domain' argument.".format(e)) return # this is optional, only needed if the `/greet` type of # messages in the stories should be replaced with actual # messages (e.g. `hello`) if nlu_data_path is not None: import rasa.shared.nlu.training_data.loading nlu_training_data = rasa.shared.nlu.training_data.loading.load_data( nlu_data_path) else: nlu_training_data = None logger.info("Starting to visualize stories...") telemetry.track_visualization() await agent.visualize(stories_path, output_path, max_history, nlu_training_data=nlu_training_data) full_output_path = "file://{}".format(os.path.abspath(output_path)) logger.info(f"Finished graph creation. Saved into {full_output_path}") import webbrowser webbrowser.open(full_output_path)