Пример #1
0
    def __init__(self, opt, world_path, max_workers, manager, is_debug=False):
        self._world_module = utils.get_world_module(world_path)
        self.executor = futures.ThreadPoolExecutor(max_workers=max_workers)
        self.debug = is_debug
        self._log("Found world module: {}".format(self._world_module))
        opt["is_debug"] = is_debug
        self.manager = manager
        self.system_done = False
        self.opt = opt
        self.tasks = {}  # task ID to task
        self.initialized = False

        def _is_done_initializing(fut):
            e = fut.exception()
            if e is not None:
                self._log('`module_initialize` returned with error {}'.format(
                    repr(e)))
                if self.debug:
                    raise e
            if fut.result():
                print(fut.result())
            if self.debug:
                print("DEBUG: Call to `module_initialize` has completed...")
            self.initialized = True

        if hasattr(self._world_module, "module_initialize"):
            self._log("Initializing world module...")
            # perform any module intialization steps
            init_fn = self._world_module.module_initialize
            self.init_fut = self.executor.submit(init_fn, opt, manager)
            self.init_fut.add_done_callback(_is_done_initializing)
        else:
            self._log(
                "World module does not have `module initialize` function")
            self.initialized = True
Пример #2
0
    def _parse_config(self, opt: Opt):
        """
        Parse config for task.

        Use this to parse all options and settings necessary to set the variables for
        the conversation
        """
        self.debug = opt['is_debug']
        self.config = opt['config']
        self.overworld = self.config['overworld']
        self.world_path = self.config['world_path']
        self.world_module = utils.get_world_module(self.world_path)
        self.task_configs = self.config['configs']
        self.max_workers = self.config['max_workers']
        self.opt['task'] = self.config['task_name']
        # Deepcopy the opts so the manager opts aren't changed by the world runner
        self.runner_opt = copy.deepcopy(opt)
        self.world_runner = ChatServiceWorldRunner(
            self.runner_opt, self.world_path, self.max_workers, self, opt['is_debug']
        )  # Replace with base runner
        self.max_agents_for = {
            task: cfg.agents_required for task, cfg in self.task_configs.items()
        }
        self.onboard_map = {
            task: cfg.onboarding_name for task, cfg in self.task_configs.items()
        }
        self.taskworld_map = {
            task: cfg.task_name for task, cfg in self.task_configs.items()
        }
        self.service_reference_id = None
        self.parse_additional_args(opt)