async def test_testing_with_utilizing_retrieval_intents( response_selector_agent: Agent, response_selector_test_stories: Path, tmp_path: Path): result = await rasa.core.test.test( stories=response_selector_test_stories, agent=response_selector_agent, e2e=True, out_directory=str(tmp_path), disable_plotting=True, warnings=False, ) failed_stories_path = tmp_path / "failed_test_stories.yml" failed_stories = read_yaml(read_file(failed_stories_path, "utf-8")) # check that the intent is shown correctly in the failed test stories file target_intents = { "test 0": "chitchat/ask_name", "test 1": "chitchat/ask_name", "test 2": "chitchat", "test 3": "chitchat", } for story in failed_stories["stories"]: test_name = story["story"].split("-")[0].strip() assert story["steps"][0]["intent"] == target_intents[test_name] # check that retrieval intent for actions is retrieved correctly # and only when it's needed. target_actions = { "utter_chitchat": "utter_chitchat", "utter_chitchat/ask_name": "utter_chitchat/ask_name", "utter_chitchat/ask_weather": "utter_chitchat/ask_name", "utter_goodbye": "utter_chitchat/ask_name", } predicted_actions = result["actions"][::2] for predicted_action in predicted_actions: assert (target_actions[predicted_action["action"]] == predicted_action["predicted"])
def is_markdown_nlg_file(filename: Union[Text, Path]) -> bool: """Checks if given file contains NLG training data. Args: filename: Path to the training data file. Returns: `True` if file contains NLG training data, `False` otherwise. """ content = io_utils.read_file(filename) return re.search(NLG_MARKDOWN_MARKER_REGEX, content) is not None
def json_unpickle(file_name: Union[Text, Path]) -> Any: """Unpickle an object from file using json. Args: file_name: the file to load the object from Returns: the object """ import jsonpickle.ext.numpy as jsonpickle_numpy import jsonpickle jsonpickle_numpy.register_handlers() file_content = read_file(file_name) return jsonpickle.loads(file_content)
def read_config_file(filename: Text) -> Dict[Text, Any]: """Parses a yaml configuration file. Content needs to be a dictionary Args: filename: The path to the file which should be read. """ content = read_yaml(read_file(filename)) if content is None: return {} elif isinstance(content, dict): return content else: raise ValueError("Tried to load invalid config file '{}'. " "Expected a key value mapping but found {}" ".".format(filename, type(content)))