def start_training(bot: str, user: str): """ Prevents training of the bot if the training session is in progress otherwise start training """ exception = None model_file = None training_status = None ModelProcessor.set_training_status( bot=bot, user=user, status=MODEL_TRAINING_STATUS.INPROGRESS.value, ) try: model_file = train_model_for_bot(bot) training_status = MODEL_TRAINING_STATUS.DONE.value except Exception as e: logging.exception(e) training_status = MODEL_TRAINING_STATUS.FAIL.value exception = str(e) raise AppException(exception) finally: ModelProcessor.set_training_status( bot=bot, user=user, status=training_status, model_path=model_file, exception=exception, ) AgentProcessor.reload(bot) return model_file
async def train(current_user: User = Depends(auth.get_current_user)): model_file = await train_model_from_mongo(current_user.get_bot()) AgentProcessor.reload(current_user.get_bot()) return { "data": { "file": model_file }, "message": "Model trained successfully" }