async def save_from_path(self, path: Text, bot: Text, overwrite: bool = True, user="******"): try: story_files, nlu_files = get_core_nlu_files( os.path.join(path, DEFAULT_DATA_PATH)) nlu = utils.training_data_from_paths(nlu_files, "en") domain = Domain.from_file(os.path.join(path, DEFAULT_DOMAIN_PATH)) domain.check_missing_templates() story_steps = await StoryFileReader.read_from_files( story_files, domain) config = read_config_file(os.path.join(path, DEFAULT_CONFIG_PATH)) self.save_domain(domain, bot, user) self.save_stories(story_steps, bot, user) self.save_nlu(nlu, bot, user) self.save_config(config, bot, user) except InvalidDomain as e: logging.info(e) raise AppException("""Failed to validate yaml file. Please make sure the file is initial and all mandatory parameters are specified""" ) except Exception as e: logging.info(e) raise AppException(e)
def load_domain(self, bot: Text) -> Domain: domain_dict = { DOMAIN.INTENTS.value: self.__prepare_training_intents(bot), DOMAIN.ACTIONS.value: self.__prepare_training_actions(bot), DOMAIN.SLOTS.value: self.__prepare_training_slots(bot), DOMAIN.SESSION_CONFIG.value: self.__prepare_training_session_config(bot), DOMAIN.RESPONSES.value: self.__prepare_training_responses(bot), DOMAIN.FORMS.value: self.__prepare_training_forms(bot), DOMAIN.ENTITIES.value: self.__prepare_training_domain_entities(bot), } return Domain.from_dict(domain_dict)
def create_zip_file(nlu: TrainingData, domain: Domain, stories: StoryGraph, config: Dict, bot: Text): directory = Utility.save_files( nlu.nlu_as_markdown().encode(), domain.as_yaml().encode(), stories.as_story_string().encode(), yaml.dump(config).encode(), ) zip_path = os.path.join(tempfile.gettempdir(), bot) zip_file = shutil.make_archive(zip_path, format="zip", root_dir=directory) shutil.rmtree(directory) return zip_file
def save_from_path(self, path: Text, bot: Text, user="******"): try: story_files, nlu_files = get_core_nlu_files( os.path.join(path, DEFAULT_DATA_PATH)) nlu = utils.training_data_from_paths(nlu_files, "en") domain = Domain.from_file(os.path.join(path, DEFAULT_DOMAIN_PATH)) loop = asyncio.new_event_loop() story_steps = loop.run_until_complete( StoryFileReader.read_from_files(story_files, domain)) self.save_domain(domain, bot, user) self.save_stories(story_steps, bot, user) self.save_nlu(nlu, bot, user) self.__save_config( read_config_file(os.path.join(path, DEFAULT_CONFIG_PATH)), bot, user) except InvalidDomain as e: logging.info(e) raise AppException("""Failed to validate yaml file. Please make sure the file is initial and all mandatory parameters are specified""" ) except Exception as e: logging.info(e) raise AppException(e)