Esempio n. 1
0
def get_agent_for_user(user):
    agent = agents_by_user.get(user.id)

    if not agent:
        logging.info('Agent does not exist for "%s", creating it' % user.id)

        interpreter = SnipsInterpreter(user.profile.language[:2],
                                       CONFIG.getpath(CACHE_DIR))
        interpreter.fit_from_skill_data()

        agent = Agent(interpreter, uid=user.id)

        agents_by_user[user.id] = agent
    else:
        logging.info('Agent found matching this user!')

    user_settings = user.setting_set.all()
    user_settings_dict = {
        setting.name: setting.value
        for setting in user_settings
    }

    # Update agent meta with user settings
    agent.meta.update(user_settings_dict)

    return agent
Esempio n. 2
0
def list_skills():  # pragma: no cover
    """List installed skills for this instance.
    """
    import_skills(CONFIG.getpath(SKILLS_DIR))

    metas = instantiate_skill_manager().get()

    for meta in metas:
        click.echo(meta)
Esempio n. 3
0
def instantiate_and_fit_interpreter(training_file=None):  # pragma: no cover
    if not training_file:
        import_skills(CONFIG.getpath(SKILLS_DIR), CONFIG.getbool(WATCH))

    try:
        from pytlas.understanding.snips import SnipsInterpreter  # pylint: disable=import-outside-toplevel

        interpreter = SnipsInterpreter(CONFIG.get(LANGUAGE),
                                       CONFIG.getpath(CACHE_DIR))

        if training_file:
            interpreter.fit_from_file(training_file)
        else:
            interpreter.fit_from_skill_data()

        return interpreter
    except ImportError:
        logging.critical(
            'Could not import the "snips" interpreter, is "snips-nlu" installed?'
        )
Esempio n. 4
0
def serve(data_dir, default):
    """Starts the server.
    """
    agents_factory = FromFile(data_dir, default)

    # Let's load the configuration and load the skills
    CONFIG.load_from_file(agents_factory._default_conf_path)  # pylint: disable=protected-access
    import_skills(CONFIG.getpath(SKILLS_DIR, os.path.join(data_dir, 'skills')),
                  CONFIG.getbool(WATCH))

    server = Server(agents_factory)

    with MQTTChannel() as mqtt:
        mqtt.attach(server)
        input('Press any key, anytime to stop the broker')
Esempio n. 5
0
def instantiate_skill_manager():  # pragma: no cover
    return SkillsManager(CONFIG.getpath(SKILLS_DIR),
                         CONFIG.get(LANGUAGE),
                         default_git_url=CONFIG.get(REPO_URL))
Esempio n. 6
0
def instantiate_agent_prompt(sentence=None):  # pragma: no cover
    interpreter = instantiate_and_fit_interpreter()

    Prompt(Agent(interpreter,
                 transitions_graph_path=CONFIG.getpath(GRAPH_FILE)),
           parse_message=sentence).cmdloop()
Esempio n. 7
0
 def ready(self):
     install_logs(CONFIG.getbool(VERBOSE),
                  CONFIG.getbool(DEBUG, section='web'))
     import_skills(CONFIG.getpath(SKILLS_DIR))