Read the yaml config of the given task in `tasks` directory.
(task, tasks_dir, postfix='')
| 68 | |
| 69 | |
| 70 | def prepare_task_config(task, tasks_dir, postfix=''): |
| 71 | """Read the yaml config of the given task in `tasks` directory.""" |
| 72 | all_task_dir = tasks_dir |
| 73 | task_path = os.path.join(all_task_dir, task) |
| 74 | # print(all_task_dir, task) |
| 75 | print('all_task_dir: ', all_task_dir) |
| 76 | print('task: ', task) |
| 77 | print('task_path: ', task_path) |
| 78 | print('task_path exist? ', os.path.exists(task_path), task_path) |
| 79 | config_path = os.path.join(task_path, f"config_{postfix}.yaml") |
| 80 | print(config_path) |
| 81 | if not os.path.exists(task_path): |
| 82 | all_tasks = [] |
| 83 | for task in os.listdir(all_task_dir): |
| 84 | if ( |
| 85 | os.path.isdir(os.path.join(all_task_dir, task)) |
| 86 | and task != "__pycache__" |
| 87 | ): |
| 88 | all_tasks.append(task) |
| 89 | for subtask in os.listdir(os.path.join(all_task_dir, task)): |
| 90 | if ( |
| 91 | os.path.isdir(os.path.join(all_task_dir, task, subtask)) |
| 92 | and subtask != "__pycache__" |
| 93 | ): |
| 94 | all_tasks.append(f"{task}/{subtask}") |
| 95 | raise ValueError(f"Task {task} not found. Available tasks: {all_tasks}") |
| 96 | if not os.path.exists(config_path): |
| 97 | raise ValueError( |
| 98 | "You should include the config.yaml file in the task directory" |
| 99 | ) |
| 100 | task_config = yaml.safe_load(open(config_path)) |
| 101 | |
| 102 | for i, agent_configs in enumerate(task_config["agents"]): |
| 103 | agent_configs["memory"] = load_memory(agent_configs.get("memory", {})) |
| 104 | if agent_configs.get("tool_memory", None) is not None: |
| 105 | agent_configs["tool_memory"] = load_memory(agent_configs["tool_memory"]) |
| 106 | llm = load_llm(agent_configs.get("llm", "text-davinci-003")) |
| 107 | agent_configs["llm"] = llm |
| 108 | |
| 109 | memory_manipulator = load_memory_manipulator( |
| 110 | agent_configs.get("memory_manipulator", {}) |
| 111 | ) |
| 112 | agent_configs["memory_manipulator"] = memory_manipulator |
| 113 | |
| 114 | agent_configs["tools"] = load_tools(agent_configs.get("tools", [])) |
| 115 | |
| 116 | # Build the output parser |
| 117 | output_parser_config = agent_configs.get("output_parser", {"type": "dummy"}) |
| 118 | if output_parser_config.get("type", None) == "role_assigner": |
| 119 | output_parser_config["cnt_critic_agents"] = task_config.get( |
| 120 | "cnt_critic_agents", 0 |
| 121 | ) |
| 122 | output_parser_name = output_parser_config.pop("type", task) |
| 123 | agent_configs["output_parser"] = output_parser_registry.build( |
| 124 | output_parser_name, **output_parser_config |
| 125 | ) |
| 126 | |
| 127 | return task_config |
no test coverage detected