(data_dir, dependency_type)
| 58 | @click.option('--data_dir', default='data_huggingface', help='Path to the data directory') |
| 59 | @click.option('--dependency_type', default='resource') |
| 60 | def formulate(data_dir, dependency_type): |
| 61 | rf = open(f"{data_dir}/data_raw.json", "r") |
| 62 | wf_format = open(f"{data_dir}/data.json", "w") |
| 63 | wf_error = open(f"{data_dir}/data_error.json", "w") |
| 64 | wf_ur = open(f"{data_dir}/user_requests.json", "w") |
| 65 | |
| 66 | all = 0 |
| 67 | format = 0 |
| 68 | for line in rf: |
| 69 | all += 1 |
| 70 | data = json.loads(line) |
| 71 | method = data["method"] |
| 72 | n_tools = data["number_of_tools"] |
| 73 | seed = data["seed"] |
| 74 | _id = data["id"] |
| 75 | sampled_nodes = data["sampled_nodes"] |
| 76 | sampled_links = data["sampled_links"] |
| 77 | for sampled_node in sampled_nodes: |
| 78 | sampled_node["task"] = sampled_node["id"] |
| 79 | sampled_node.pop("id") |
| 80 | if dependency_type == "resource": |
| 81 | sampled_node["task"] = sampled_node["task"].replace("_", " ") |
| 82 | if "input" in sampled_node: |
| 83 | sampled_node["input-type"] = sampled_node["input"] |
| 84 | sampled_node.pop("input") |
| 85 | sampled_node["output-type"] = sampled_node["output"] |
| 86 | sampled_node.pop("output") |
| 87 | else: |
| 88 | sampled_node["arguments"] = sampled_node["parameters"] |
| 89 | sampled_node.pop("parameters") |
| 90 | user_request, task_steps, links, nodes, check_by_teacher = formulate_sample(data, dependency_type) |
| 91 | if user_request is None: |
| 92 | wf_error.write(line) |
| 93 | continue |
| 94 | format += 1 |
| 95 | result = { |
| 96 | "id": _id, |
| 97 | "seed": seed, |
| 98 | "type": method, |
| 99 | "n_tools": n_tools, |
| 100 | "sampled_nodes": sampled_nodes, |
| 101 | "sampled_links": sampled_links, |
| 102 | "user_request": user_request, |
| 103 | "task_steps": task_steps, |
| 104 | "task_nodes": nodes, |
| 105 | "task_links": links, |
| 106 | "check_by_teacher": check_by_teacher, |
| 107 | } |
| 108 | wf_format.write(json.dumps(result)+"\n") |
| 109 | ur_result = { |
| 110 | "id": _id, |
| 111 | "user_request": user_request, |
| 112 | } |
| 113 | wf_ur.write(json.dumps(ur_result)+"\n") |
| 114 | wf_format.close() |
| 115 | wf_error.close() |
| 116 | wf_ur.close() |
| 117 | rf.close() |
no test coverage detected