Example #1
0
def start_training() -> NoReturn:
    """Starts interactive learning session.

    Starts interactive learning using command, `rasa interactive`.

    Note: It will use the default Charlotte model,
    `./models/charlotte.tar.gz` for training. Training will be skipped
    if the training data and config have not changed.
    """
    # You can find the reference code here:
    # https://rasa.com/docs/rasa/user-guide/command-line-interface/
    try:
        # Checks if `charlotte.tar.gz` exists.
        # Story visualization is disabled as a personal preference. You
        # can enable it by removing `--skip-visualization` from the
        # below code.
        if model_check(ai_lower):
            charlotte = model_check(ai_lower)
            ep = ai_file['endpoints']
            call(f'rasa interactive --model {charlotte} --skip-visualization '
                 f'--endpoints {ep} --e2e --dump-stories')
        else:
            # Similar to `test_nlu` function, it renders the model if it
            # does not exist.
            option = confirm(
                f'Sorry {lower}, I could not find NLU model in "./models/" '
                f'directory. Shall I create one now?')
            if option is True:
                render_model()
            else:
                show('Model not created.')
    except Exception as error:
        print('An error occured while performing this operation because of'
              f' {error} in function "{stack()[0][3]}" on line'
              f' {exc_info()[-1].tb_lineno}.')
Example #2
0
def test_nlu() -> NoReturn:
    """Tests NLU model.

    Runs NLU test session for testing the model. This function predicts
    the intent of given statement and extracts the entities if present
    in it.

    Note: It will use the default Charlotte model,
    `./models/charlotte.tar.gz` for testing.
    """
    # You can find the reference code here:
    # https://rasa.com/docs/rasa/user-guide/command-line-interface/
    try:
        # Checks if `charlotte.tar.gz` exists.
        if model_check(ai_lower):
            charlotte = model_check(ai_lower)
            call(f'rasa shell nlu model-as-positional-argument "{charlotte}"')
        else:
            # Renders the model if it does not exist.
            option = confirm(
                f'Sorry {lower}, I could not find NLU model in "./models/" '
                f'directory. Shall I create one now?')
            if option is True:
                render_model()
            else:
                show('Model not created.')
    except Exception as error:
        print('An error occured while performing this operation because of'
              f' {error} in function "{stack()[0][3]}" on line'
              f' {exc_info()[-1].tb_lineno}.')
Example #3
0
def quit() -> NoReturn:
    """Terminates the code with a confirmation."""
    from sys import exit

    try:
        option = confirm('Are you sure you want to leave?')
        if option is True:
            exit()
    except Exception as error:
        print('An error occured while performing this operation because of'
              f' {error} in function "{stack()[0][3]}" on line'
              f' {exc_info()[-1].tb_lineno}.')
Example #4
0
def render_model() -> NoReturn:
    """Renders model.

    Creates models using your NLU data and stories. The function renders
    model by overwriting the previous model (if model has same name).

    Note: This function trains a Rasa model that combines Rasa NLU and
    Core models. If you only want to choose specific model, you can use
    this function to do so.
    """
    # You can find the reference code here:
    # https://rasa.com/docs/rasa/user-guide/command-line-interface/
    try:
        # Asks which model to render.
        type = choose(choice(cmdline_options['choose_model']),
                      nlu='NLU',
                      core='Core',
                      both='Both')
        # Builds domain file with the my details.
        _build_domain()
        make_dir(ai_dir['models'])
        rename = confirm(choice(cmdline_options['rename_model']))
        # If the model is to be renamed, it will take input and render
        # that model. Else, it will use `charlotte` as the default name.
        if rename is True:
            name = answer(f'{title}, what would you like to call it?').lower()
        else:
            name = ai_lower
            show('This will overwrite the existing main model.')
        # Appending model type to the name.
        if type == 'nlu':
            model = f'{type} --fixed-model-name "{name}_nlu"'
            call(f'rasa train {model}')
        elif type == 'core':
            model = f'{type} --fixed-model-name "{name}_core"'
            call(f'rasa train {model} --force --debug-plots --dump-stories')
        else:
            model = f'--fixed-model-name "{name}"'
            call(f'rasa train {model} --force --debug-plots --dump-stories')
    except Exception as error:
        print('An error occured while performing this operation because of'
              f' {error} in function "{stack()[0][3]}" on line'
              f' {exc_info()[-1].tb_lineno}.')
Example #5
0
                        clear_screen='Clear screen',
                        exit='Exit')
        if option is 'render_model':
            render_model()
        elif option is 'start_training':
            start_training()
        elif option is 'evaluate_model':
            evaluate_model()
        elif option is 'test_nlu':
            test_nlu()
        elif option is 'get_nlu_stats':
            get_nlu_stats()
        elif option is 'start_action_server':
            call(f'rasa run actions -p {ACTION_SERVER_PORT}', shell=True)
        elif option is 'user_command':
            option = confirm(choice(cmdline_options['user_command']))
            if option is True:
                call(answer(choice(cmdline_options['terminal_set'])),
                     shell=True)
        elif option is 'clear_screen':
            option = confirm(choice(cmdline_options['clear_screen']))
            if option is True:
                call('cls', shell=True)
        elif option is 'exit':
            option = confirm(choice(cmdline_options['confirm_quit']))
            if option is True:
                exit()
except Exception as error:
    print('An error occurred while performing this operation because of'
          f' {error} in function "{stack()[0][3]}" on line'
          f' {exc_info()[-1].tb_lineno}.')
Example #6
0
    'this session.'

# Code starts here:
# Checks if all the necessary environment variables are present or not.
try:
    if all([
            os.environ.get(_MASTER_KEY),
            os.environ.get(_ALIAS),
            os.environ.get(_USERNAME),
            os.environ.get(_MOBILE),
            os.environ.get(_HOTWORD)
    ]) is False:
        show('Key check failed! Creating user profile.')
        # If no master key is detected.
        if os.environ.get(_MASTER_KEY) is None:
            start = confirm(_INITIAL_SETUP)
            if start is False:
                show(_PROFILE_SKIPPED)
                exit()
            else:
                warning = confirm(_RESTART_REQUIRED)
                if warning is True:
                    if os.environ.get(_MASTER_KEY) is None:
                        show(_TIP_1)
                        key = keygen(_MASTER_KEY,
                                     secure(_GIVE_PASSWORD),
                                     return_key=True)
                else:
                    show(_PROFILE_SKIPPED)
                    exit()
        else: