()
| 48 | |
| 49 | |
| 50 | def cli_main(): |
| 51 | dataloader = get_dataloader(args.task, args.dataset_path) |
| 52 | os.makedirs(args.output_path, exist_ok=True) |
| 53 | shutil.copyfile( |
| 54 | f"{args.tasks_dir}/{args.task}/config_{args.postfix}.yaml", |
| 55 | f"{args.output_path}/config_{args.postfix}.yaml", |
| 56 | ) |
| 57 | print(len(dataloader.examples)) |
| 58 | if args.debug and len(dataloader.examples) > 2: |
| 59 | dataloader.examples = dataloader.examples[:2] |
| 60 | print('--->', len(dataloader.examples)) |
| 61 | if args.skip_cnt == 0: |
| 62 | skip_cnt = 0 |
| 63 | if not args.overwrite and os.path.exists(f"{args.output_path}/results_{args.postfix}.jsonl"): |
| 64 | with open(f"{args.output_path}/results_{args.postfix}.jsonl", "r") as f: |
| 65 | for line in f: |
| 66 | if line.strip(): |
| 67 | skip_cnt += 1 |
| 68 | else: |
| 69 | skip_cnt = args.skip_cnt |
| 70 | f = open(f"{args.output_path}/results_{args.postfix}.jsonl", "w" if args.overwrite else "a") |
| 71 | logger.info(f"Skip {skip_cnt} examples, start from {skip_cnt + 1}.") |
| 72 | |
| 73 | for i, example in enumerate(tqdm(dataloader, total=len(dataloader.examples))): |
| 74 | if i < skip_cnt: |
| 75 | continue |
| 76 | logger.info(f"Input: {example['input']}\nAnswer: {example['answer']}") |
| 77 | agentverse = TaskSolving.from_task(args.task, args.tasks_dir, args.postfix) |
| 78 | agentverse.environment.set_task_description(example["input"]) |
| 79 | plan, result, logs, decision_making_process = agentverse.run() |
| 80 | total_spent = agentverse.environment.get_spend() |
| 81 | f.write( |
| 82 | json.dumps( |
| 83 | { |
| 84 | "input": example["input"], |
| 85 | "response": plan, |
| 86 | "label": example["answer"], |
| 87 | "logs": logs, |
| 88 | "decision_making_process": decision_making_process, |
| 89 | "spent": total_spent |
| 90 | }, ensure_ascii=False |
| 91 | ) |
| 92 | + "\n" |
| 93 | ) |
| 94 | f.flush() |
| 95 | f.close() |
| 96 | |
| 97 | |
| 98 | if __name__ == "__main__": |
no test coverage detected