def _convert_to_yaml(args: argparse.Namespace, converter: TrainingDataConverter) -> None: output = Path(args.out) if not os.path.exists(output): print_error_and_exit( f"The output path '{output}' doesn't exist. Please make sure to specify " f"an existing directory and try again.") training_data = Path(args.data) if not os.path.exists(training_data): print_error_and_exit( f"The training data path {training_data} doesn't exist " f"and will be skipped.") num_of_files_converted = 0 if os.path.isfile(training_data): if _convert_file_to_yaml(training_data, output, converter): num_of_files_converted += 1 elif os.path.isdir(training_data): for root, _, files in os.walk(training_data, followlinks=True): for f in sorted(files): source_path = Path(os.path.join(root, f)) if _convert_file_to_yaml(source_path, output, converter): num_of_files_converted += 1 if num_of_files_converted: print_info( f"Converted {num_of_files_converted} file(s), saved in '{output}'." ) else: print_warning( f"Didn't convert any files under '{training_data}' path. " "Did you specify the correct file/directory?")
def _convert_nlg_data(args: argparse.Namespace) -> None: from rasa.nlu.training_data.converters.nlg_markdown_to_yaml_converter import ( NLGMarkdownToYamlConverter, ) if args.format == "yaml": _convert_to_yaml(args, NLGMarkdownToYamlConverter()) else: print_error_and_exit( "Could not recognize output format. Supported output formats: " "'yaml'. Specify the desired output format with '--format'.")
def run(args: argparse.Namespace) -> None: import questionary print_success("Welcome to Rasa! 🤖\n") if args.no_prompt: print( f"To get started quickly, an " f"initial project will be created.\n" f"If you need some help, check out " f"the documentation at {DOCS_BASE_URL}.\n" ) else: print( f"To get started quickly, an " f"initial project will be created.\n" f"If you need some help, check out " f"the documentation at {DOCS_BASE_URL}.\n" f"Now let's start! 👇🏽\n" ) if args.init_dir is not None: path = args.init_dir else: path = ( questionary.text( "Please enter a path where the project will be " "created [default: current directory]", ) .skip_if(args.no_prompt, default="") .ask() ) # set the default directory. we can't use the `default` property # in questionary as we want to avoid showing the "." in the prompt as the # initial value. users tend to overlook it and it leads to invalid # paths like: ".C:\mydir". # Can't use `if not path` either, as `None` will be handled differently (abort) if path == "": path = "." if args.no_prompt and not os.path.isdir(path): print_error_and_exit(f"Project init path '{path}' not found.") if path and not os.path.isdir(path): _ask_create_path(path) if path is None or not os.path.isdir(path): print_cancel() if not args.no_prompt and len(os.listdir(path)) > 0: _ask_overwrite(path) telemetry.track_project_init(path) init_project(args, path)
def _convert_nlu_data(args: argparse.Namespace) -> None: from rasa.nlu.training_data.converters.nlu_markdown_to_yaml_converter import ( NLUMarkdownToYamlConverter, ) if args.format in ["json", "md"]: convert_training_data(args.data, args.out, args.format, args.language) elif args.format == "yaml": _convert_to_yaml(args, NLUMarkdownToYamlConverter()) else: print_error_and_exit( "Could not recognize output format. Supported output formats: 'json', " "'md', 'yaml'. Specify the desired output format with '--format'.")
def _ask_create_path(path: Text) -> None: import questionary should_create = questionary.confirm( f"Path '{path}' does not exist 🧐. Create path?").ask() if should_create: try: os.makedirs(path) except (PermissionError, OSError, FileExistsError) as e: print_error_and_exit(f"Failed to create project path at '{path}'. " f"Error: {e}") else: print_success("Ok, will exit for now. You can continue setting up by " "running 'rasa init' again 🙋🏽♀️") sys.exit(0)
def run(args: argparse.Namespace) -> None: import questionary print_success("Welcome to Rasa! 🤖\n") if args.no_prompt: print(f"To get started quickly, an " f"initial project will be created.\n" f"If you need some help, check out " f"the documentation at {DOCS_BASE_URL}.\n") else: print(f"To get started quickly, an " f"initial project will be created.\n" f"If you need some help, check out " f"the documentation at {DOCS_BASE_URL}.\n" f"Now let's start! 👇🏽\n") if args.init_dir is not None: path = args.init_dir else: path = (questionary.text( "Please enter a path where the project will be " "created [default: current directory]", default=".", ).skip_if(args.no_prompt, default=".").ask()) if args.no_prompt and not os.path.isdir(path): print_error_and_exit(f"Project init path '{path}' not found.") if path and not os.path.isdir(path): _ask_create_path(path) if path is None or not os.path.isdir(path): print_cancel() if not args.no_prompt and len(os.listdir(path)) > 0: _ask_overwrite(path) telemetry.track_project_init(path) init_project(args, path)