def generate_conversation_md_from_domain(path_to_language: str): """Generates test stories based on the intents available in the domain. Complex stories are not generated. Args: path_to_language (str): path to language folder. If it's a single-language bot this will be the bot root's folder. """ domain = load_yaml(join(path_to_language, "domain.yml")) intents_list = domain.get("intents", None) all_nlu = [] for filename in listdir(join(path_to_language, "data")): if isfile(join(path_to_language, "data", filename)): if "stories" not in filename: nlu = load_md(join(path_to_language, "data", filename)) all_nlu.append(nlu) all_nlu = [item for sublist in all_nlu for item in sublist] if not intents_list: print_error("No intents were found.") exit(0) elif intents_list: output_path = join(path_to_language, "tests", "conversation_tests.md") if not exists(join(path_to_language, "tests")): mkdir(join(path_to_language, "tests")) with open(output_path, "w", encoding="utf-8") as out_f: for intent in intents_list: out_f.write(f"## {intent}\n") out_f.write( f"* {intent}: {get_intent_example(intent, all_nlu)}\n" ) out_f.write(f" - utter_{intent}\n") out_f.write("\n")
def verify_endpoint_validity(base_url: str, username: str, password: str, env_name: str = None): with loading_indicator('Verifying the endpoint validity...') as spinner: if not is_endpoint_config_valid(base_url, username, password, env_name): spinner.stop() print_error('The endpoint configuration is invalid.\n') return
def format_results(language_path: str, timestamp: str): """ Format the results output by Rasa. This includes: - confusion list stating how many times two intents are being confused - misclassified intents: the same as above but it shows the specific utters - statistics table: containing metrics like accuracy, precision, etc. Args: language_path (str): path to language folder. timestamp (str): timestamp of when the test is run. """ try: confusion_list = confusion_table_df(language_path, timestamp) misclassified_intents = misclassified_intents_df(language_path, timestamp) statistics_table = stats_table(language_path, timestamp) with pd.ExcelWriter( join(language_path, "results", timestamp, "intent_details.xlsx"), engine="xlsxwriter", ) as xlsx_writer: confusion_list.to_excel( excel_writer=xlsx_writer, sheet_name="Confusion Table", index=False ) worksheet = xlsx_writer.sheets["Confusion Table"] for i, col in enumerate(confusion_list.columns): column_len = max( confusion_list[col].astype(str).str.len().max(), len(col) + 2 ) worksheet.set_column(i, i, column_len) misclassified_intents.to_excel( excel_writer=xlsx_writer, sheet_name="Misclassified Intents", index=False ) worksheet = xlsx_writer.sheets["Misclassified Intents"] for i, col in enumerate(misclassified_intents.columns): column_len = max( misclassified_intents[col].astype(str).str.len().max(), len(col) + 2, ) worksheet.set_column(i, i, column_len) statistics_table.to_excel( excel_writer=xlsx_writer, sheet_name="Intent Statistics", index=False ) worksheet = xlsx_writer.sheets["Intent Statistics"] for i, col in enumerate(statistics_table.columns): column_len = max( statistics_table[col].astype(str).str.len().max(), len(col) + 2, ) worksheet.set_column(i, i, column_len) except Exception: print_error("One or more files necessary for the intent_details.xlsx file was not output by Rasa and thus this file cannot be generated.\n")
def activate_environment(settings, env_name): env_name = env_name[0] environment = settings.get_environment(env_name) if not environment: print_error( "The environment you're trying to activate is not configured yet.\n" ) exit(0) verify_endpoint_validity(environment.base_url, environment.api_auth_setting.username, environment.api_auth_setting.password, environment) settings.set_current_environment(environment) print_success( f"The connection to the {env_name} environment was successfully established." )
def generate_stories_md(path_to_language: str, multi_language_bot: bool): domain = load_yaml(join(path_to_language, "domain.yml")) intents_list = domain.get("intents", None) if not intents_list: print_error("No intents were found.") exit(0) elif intents_list: intents_list = clean_intents(intents_list) if multi_language_bot: output_path = join(abspath("."), "languages", "stories.md") else: output_path = join(path_to_language, "data", "stories.md") with open(output_path, "w", encoding="utf-8") as out_f: for intent in intents_list: out_f.write(f"## {intent}\n") out_f.write(f"* {intent}\n") out_f.write(f" - utter_{intent}\n") out_f.write("\n")
def command(api_key: str): """ Initialize a new session using a ROBO.AI API key, Args: api_key (str): API key """ settings = ToolSettings() current_environment = settings.get_current_environment( ) # this should be an object now robo = get_robo_client(current_environment) try: with loading_indicator('Authenticating...'): tokens = robo.oauth.authenticate(api_key) current_environment.api_key = api_key current_environment.api_auth_token = tokens.access_token settings.update_environment(current_environment) print_success('Successfully authenticated!\n') except InvalidCredentialsError: print_error('The API key is invalid.\n')
def check_covered_intents(language_path: list, multi_language_bot: bool): for language in language_path: intents = load_yaml(join(language, "domain.yml")).get("intents", None) if intents is None: print_error("No intents were found.\n") exit(0) else: intents = clean_intents(intents) check_specific_stories = False if multi_language_bot: stories_dir_path = join(abspath("."), "languages") check_specific_stories = True else: stories_dir_path = join(language, "data") for filename in listdir(stories_dir_path): if isfile(join(stories_dir_path, filename)): if "stories" in filename: lines = load_md(join(stories_dir_path, filename)) for line in lines: for intent in intents: if intent in line: intents.remove(intent) break if check_specific_stories: lang = basename(language) for filename in listdir(join(stories_dir_path, lang, "data")): if isfile(join(stories_dir_path, lang, "data", filename)): if "stories" in filename: lines = load_md(join(stories_dir_path, lang, "data", filename)) for line in lines: for intent in intents: if intent in line: intents.remove(intent) break if intents: print("The following intents are not covered in your stories:") print(*intents, sep="\n")
def check_covered_intents(language_path: str) -> bool: intents = load_yaml(join(language_path, "domain.yml")).get("intents", None) if intents is None: print_error("No intents were found.\n") exit(0) else: intents = clean_intents(intents) for filename in listdir(join(language_path, "tests")): if filename.endswith(".md"): lines = load_md(join(language_path, "tests", filename)) for line in lines: for intent in intents: if intent in line: intents.remove(intent) break if intents: print( "The following intents are not covered in your test stories:" ) print(*intents, sep="\n") should_test = proceed_with_test("Continue testing?\n") else: should_test = True return should_test