You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

init_tasks.py 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #
  2. # Run this file to download the human_eval dataset, and create a corresponding testbed scenario:
  3. # (default: ../scenarios/human_eval_two_agents_gpt4.jsonl and ./scenarios/human_eval_two_agents_gpt35.jsonl)
  4. #
  5. import json
  6. import os
  7. import re
  8. import sys
  9. from huggingface_hub import snapshot_download
  10. SCRIPT_PATH = os.path.realpath(__file__)
  11. SCRIPT_NAME = os.path.basename(SCRIPT_PATH)
  12. SCRIPT_DIR = os.path.dirname(SCRIPT_PATH)
  13. SCENARIO_DIR = os.path.realpath(os.path.join(SCRIPT_DIR, os.path.pardir))
  14. TEMPLATES_DIR = os.path.join(SCENARIO_DIR, "Templates")
  15. TASKS_DIR = os.path.join(SCENARIO_DIR, "Tasks")
  16. DOWNLOADS_DIR = os.path.join(SCENARIO_DIR, "Downloads")
  17. REPO_DIR = os.path.join(DOWNLOADS_DIR, "GAIA")
  18. def download_gaia():
  19. """Download the GAIA benchmark from Hugging Face."""
  20. if not os.path.isdir(DOWNLOADS_DIR):
  21. os.mkdir(DOWNLOADS_DIR)
  22. """Download the GAIA dataset from Hugging Face Hub"""
  23. snapshot_download(
  24. repo_id="gaia-benchmark/GAIA",
  25. repo_type="dataset",
  26. local_dir=REPO_DIR,
  27. local_dir_use_symlinks=True,
  28. )
  29. def create_jsonl(name, tasks, files_dir, template):
  30. """Creates a JSONL scenario file with a given name, and template path."""
  31. if not os.path.isdir(TASKS_DIR):
  32. os.mkdir(TASKS_DIR)
  33. with open(os.path.join(TASKS_DIR, name + ".jsonl"), "wt") as fh:
  34. for task in tasks:
  35. print(f"Converting: [{name}] {task['task_id']}")
  36. # Figure out what files we need to copy
  37. template_cp_list = [template]
  38. if len(task["file_name"].strip()) > 0:
  39. template_cp_list.append(
  40. [
  41. os.path.join(files_dir, task["file_name"].strip()),
  42. task["file_name"].strip(),
  43. #os.path.join("coding", task["file_name"].strip()),
  44. ]
  45. )
  46. record = {
  47. "id": task["task_id"],
  48. "template": template_cp_list,
  49. "substitutions": {
  50. "scenario.py": {
  51. "__FILE_NAME__": task["file_name"],
  52. },
  53. "expected_answer.txt": {"__EXPECTED_ANSWER__": task["Final answer"]},
  54. "prompt.txt": {"__PROMPT__": task["Question"]},
  55. },
  56. }
  57. fh.write(json.dumps(record).strip() + "\n")
  58. ###############################################################################
  59. def main():
  60. gaia_validation_files = os.path.join(REPO_DIR, "2023", "validation")
  61. gaia_test_files = os.path.join(REPO_DIR, "2023", "test")
  62. if not os.path.isdir(gaia_validation_files) or not os.path.isdir(gaia_test_files):
  63. download_gaia()
  64. if not os.path.isdir(gaia_validation_files) or not os.path.isdir(gaia_test_files):
  65. sys.exit(f"Error: '{REPO_DIR}' does not appear to be a copy of the GAIA repository.")
  66. # Load the GAIA data
  67. gaia_validation_tasks = [[], [], []]
  68. with open(os.path.join(gaia_validation_files, "metadata.jsonl")) as fh:
  69. for line in fh:
  70. data = json.loads(line)
  71. gaia_validation_tasks[data["Level"] - 1].append(data)
  72. gaia_test_tasks = [[], [], []]
  73. with open(os.path.join(gaia_test_files, "metadata.jsonl")) as fh:
  74. for line in fh:
  75. data = json.loads(line)
  76. # A welcome message -- not a real task
  77. if data["task_id"] == "0-0-0-0-0":
  78. continue
  79. gaia_test_tasks[data["Level"] - 1].append(data)
  80. # list all directories in the Templates directory
  81. # and populate a dictionary with the name and path
  82. templates = {}
  83. for entry in os.scandir(TEMPLATES_DIR):
  84. if entry.is_dir():
  85. templates[re.sub(r"\s", "", entry.name)] = entry.path
  86. # Add coding directories if needed (these are usually empty and left out of the repo)
  87. #for template in templates.values():
  88. # code_dir_path = os.path.join(template, "coding")
  89. # if not os.path.isdir(code_dir_path):
  90. # os.mkdir(code_dir_path)
  91. # Create the various combinations of [models] x [templates]
  92. for t in templates.items():
  93. create_jsonl(
  94. f"gaia_validation_level_1__{t[0]}",
  95. gaia_validation_tasks[0],
  96. gaia_validation_files,
  97. t[1],
  98. )
  99. create_jsonl(
  100. f"gaia_validation_level_2__{t[0]}",
  101. gaia_validation_tasks[1],
  102. gaia_validation_files,
  103. t[1],
  104. )
  105. create_jsonl(
  106. f"gaia_validation_level_3__{t[0]}",
  107. gaia_validation_tasks[2],
  108. gaia_validation_files,
  109. t[1],
  110. )
  111. create_jsonl(
  112. f"gaia_test_level_1__{t[0]}",
  113. gaia_test_tasks[0],
  114. gaia_test_files,
  115. t[1],
  116. )
  117. create_jsonl(
  118. f"gaia_test_level_2__{t[0]}",
  119. gaia_test_tasks[1],
  120. gaia_test_files,
  121. t[1],
  122. )
  123. create_jsonl(
  124. f"gaia_test_level_3__{t[0]}",
  125. gaia_test_tasks[2],
  126. gaia_test_files,
  127. t[1],
  128. )
  129. if __name__ == "__main__" and __package__ is None:
  130. main()