def train_model_for_bot(bot: str): """ loads bot data from mongo into individual files for training :param bot: bot id :return: model path """ 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) rules = processor.get_rules_for_training(bot) directory = Utility.write_training_data(nlu, domain, config, stories, rules) output = os.path.join(DEFAULT_MODELS_PATH, bot) if not os.path.exists(output): os.mkdir(output) 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, core_additional_arguments={"augmentation_factor": 100}, force_training=True) Utility.delete_directory(directory) del processor del nlu del domain del stories del config Utility.move_old_models(output, model) return model
def train_model_for_bot(bot: str): """ loads bot data from mongo into individual files for training :param bot: bot id :return: model path """ 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) del processor del nlu del domain del stories del config return model
def add_bot(name: str, account: int, user: str, is_new_account: bool = False): """ add a bot to account :param name: bot name :param account: account id :param user: user id :param is_new_account: True if it is a new account :return: bot id """ if Utility.check_empty_string(name): raise AppException("Bot Name cannot be empty or blank spaces") if Utility.check_empty_string(user): raise AppException("user cannot be empty or blank spaces") Utility.is_exist( Bot, exp_message="Bot already exists!", name__iexact=name, account=account, status=True, ) bot = Bot(name=name, account=account, user=user).save().to_mongo().to_dict() bot_id = bot['_id'].__str__() if not is_new_account: AccountProcessor.add_bot_for_user(bot_id, user) BotSettings(bot=bot_id, user=user).save() processor = MongoProcessor() config = processor.load_config(bot_id) processor.add_or_overwrite_config(config, bot_id, user) processor.add_default_fallback_data(bot_id, user, True, True) return bot