Example #1
0
def train_model_for_bot(bot: str):
    """ Trains the rasa model, using the data that is loaded onto
            Mongo, through the bot files """
    processor = MongoProcessor()
    nlu = processor.load_nlu(bot)
    if not nlu.training_examples:
        raise AppException("Training data does not exists!")
    domain = processor.load_domain(bot)
    stories = processor.load_stories(bot)
    config = processor.load_config(bot)

    directory = Utility.save_files(
                nlu.nlu_as_markdown().encode(),
                domain.as_yaml().encode(),
                stories.as_story_string().encode(),
                yaml.dump(config).encode(),
            )

    output = os.path.join(DEFAULT_MODELS_PATH, bot)
    model = train(domain=os.path.join(directory,DEFAULT_DOMAIN_PATH),
                  config=os.path.join(directory,DEFAULT_CONFIG_PATH),
                  training_files=os.path.join(directory,DEFAULT_DATA_PATH),
                  output=output)
    Utility.delete_directory(directory)
    return model
Example #2
0
 async def upload_and_save(
     self,
     nlu: bytes,
     domain: bytes,
     stories: bytes,
     config: bytes,
     bot: Text,
     user: Text,
     overwrite: bool = True,
 ):
     """Upload the training data to temporary path and then save into mongo."""
     data_path = Utility.save_files(nlu, domain, stories, config)
     await self.save_from_path(data_path, bot, overwrite, user)
     Utility.delete_directory(data_path)