def _guess_reader( filename: Text, domain: Domain, template_variables: Optional[Dict] = None, use_e2e: bool = False, ) -> StoryReader: if YAMLStoryReader.is_yaml_story_file(filename): return YAMLStoryReader(domain, template_variables, use_e2e, filename) elif MarkdownStoryReader.is_markdown_story_file(filename): return MarkdownStoryReader(domain, template_variables, use_e2e, filename) raise ValueError( f"Failed to find a reader class for the story file `{filename}`. " f"Supported formats are " f"{', '.join(MARKDOWN_FILE_EXTENSIONS.union(YAML_FILE_EXTENSIONS))}.")
def is_story_file(file_path: Text) -> bool: """Checks if a file is a Rasa story file. Args: file_path: Path of the file which should be checked. Returns: `True` if it's a story file, otherwise `False`. """ from rasa.shared.core.training_data.story_reader.yaml_story_reader import ( YAMLStoryReader, ) from rasa.shared.core.training_data.story_reader.markdown_story_reader import ( MarkdownStoryReader, ) return YAMLStoryReader.is_yaml_story_file( file_path) or MarkdownStoryReader.is_markdown_story_file(file_path)
async def test_is_yaml_file(file: Text, is_yaml_file: bool): assert YAMLStoryReader.is_yaml_story_file(file) == is_yaml_file