Exemplo n.º 1
0
def run(opt):
    """Run MessengerManager."""
    manager = MessengerManager(opt)
    try:
        manager.start_task()
    except BaseException:
        raise
    finally:
        manager.shutdown()
Exemplo n.º 2
0
def main():
    argparser = ParlaiParser(False, False)
    argparser.add_parlai_data_path()
    argparser.add_messenger_args()
    opt = argparser.parse_args()
    opt['task'] = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
    opt['password'] = '******'  # If password is none anyone can chat

    messenger_manager = MessengerManager(opt=opt)
    messenger_manager.setup_server()
    messenger_manager.init_new_state()

    def get_overworld(opt, agent):
        return MessengerOverworld(opt, agent)

    onboard_functions = {name: worlds[0].run for (name, worlds)
                         in MessengerOverworld.DEMOS.items()}
    messenger_manager.set_onboard_functions(onboard_functions)
    task_functions = {name: worlds[1].run for (name, worlds)
                      in MessengerOverworld.DEMOS.items()}
    assign_agent_roles = {name: worlds[1].assign_roles for (name, worlds)
                          in MessengerOverworld.DEMOS.items()}
    agents_required = {name: worlds[1].MAX_AGENTS for (name, worlds)
                       in MessengerOverworld.DEMOS.items()}
    messenger_manager.set_agents_required(agents_required)

    messenger_manager.set_overworld_func(get_overworld)
    messenger_manager.setup_socket()
    try:
        messenger_manager.start_new_run()
        messenger_manager.start_task(
            assign_role_functions=assign_agent_roles,
            task_functions=task_functions,
        )
    except BaseException:
        raise
    finally:
        messenger_manager.shutdown()
Exemplo n.º 3
0
def main():
    argparser = ParlaiParser(False, False)
    argparser.add_parlai_data_path()
    argparser.add_messenger_args()
    opt = argparser.parse_args()
    opt['task'] = os.path.basename(os.path.dirname(os.path.abspath(__file__)))

    # Initialize a SQuAD teacher agent, which we will get context from
    module_name = 'parlai.tasks.squad.agents'
    class_name = 'DefaultTeacher'
    my_module = importlib.import_module(module_name)
    task_class = getattr(my_module, class_name)
    task_opt = {}
    task_opt['datatype'] = 'train'
    task_opt['datapath'] = opt['datapath']

    messenger_manager = MessengerManager(opt=opt)
    messenger_manager.setup_server()
    messenger_manager.init_new_state()

    def get_overworld(agent):
        return MessengerOverworld(None, agent)

    def assign_agent_role(agent):
        agent[0].disp_id = 'Agent'

    def run_conversation(manager, opt, agents, task_id):
        task = task_class(task_opt)
        agent = agents[0]
        world = QADataCollectionWorld(
            opt=opt,
            task=task,
            agent=agent
        )
        while not world.episode_done():
            world.parley()
        world.shutdown()

    # World with no onboarding
    messenger_manager.set_onboard_functions({'default': None})
    task_functions = {'default': run_conversation}
    assign_agent_roles = {'default': assign_agent_role}
    messenger_manager.set_agents_required({'default': 1})

    messenger_manager.set_overworld_func(get_overworld)
    messenger_manager.setup_socket()
    try:
        messenger_manager.start_new_run()
        messenger_manager.start_task(
            assign_role_functions=assign_agent_roles,
            task_functions=task_functions,
        )
    except BaseException:
        raise
    finally:
        messenger_manager.shutdown()
Exemplo n.º 4
0
def main():
    argparser = ParlaiParser(True, True)
    argparser.add_messenger_args()
    opt = argparser.parse_args()
    print(opt)
    if opt['model'] == None and opt['model_file'] == None:
        print("Model must be specified")
        return
    bot = create_agent(opt)
    shared_bot_params = bot.share()

    messenger_manager = MessengerManager(opt=opt)
    messenger_manager.setup_server()
    messenger_manager.init_new_state()

    def get_overworld(agent):
        return MessengerOverworld(None, agent)

    def assign_agent_role(agent):
        agent[0].disp_id = 'Agent'

    def run_conversation(manager, opt, agents, task_id):
        agent = agents[0]
        this_bot = create_agent_from_shared(shared_bot_params)

        world = MessengerBotChatTaskWorld(opt=opt, agent=agent, bot=this_bot)
        while not world.episode_done():
            world.parley()
        world.shutdown()

    # World with no onboarding
    messenger_manager.set_onboard_functions({'default': None})
    task_functions = {'default': run_conversation}
    assign_agent_roles = {'default': assign_agent_role}
    messenger_manager.set_agents_required({'default': 1})

    messenger_manager.set_overworld_func(get_overworld)
    messenger_manager.setup_socket()
    try:
        messenger_manager.start_new_run()
        messenger_manager.start_task(
            assign_role_functions=assign_agent_roles,
            task_functions=task_functions,
        )
    except BaseException:
        raise
    finally:
        messenger_manager.shutdown()