rasdani commited on
Commit
33d6826
·
verified ·
1 Parent(s): a9a36d8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +133 -0
README.md CHANGED
@@ -27,3 +27,136 @@ configs:
27
  - split: train
28
  path: data/train-*
29
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  - split: train
28
  path: data/train-*
29
  ---
30
+ ```python
31
+ import re
32
+ import json
33
+ from datasets import load_dataset
34
+
35
+ PROMPT_TEMPLATE = """\
36
+ We are currently solving the following issue within our repository. Here is the issue text:
37
+ --- BEGIN ISSUE ---
38
+ {issue}
39
+ --- END ISSUE ---
40
+
41
+ Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
42
+ --- BEGIN FILES ---
43
+ {file_context}
44
+ --- END FILES ---
45
+
46
+ Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
47
+
48
+ Here is an example:
49
+
50
+ ```diff
51
+ diff --git a/examples/server_async.py b/examples/server_async.py
52
+ --- a/examples/server_async.py
53
+ +++ b/examples/server_async.py
54
+ @@ -313,4 +313,4 @@
55
+
56
+
57
+ if __name__ == "__main__":
58
+ - asyncio.run(run_async_server("."), debug=True)
59
+ + asyncio.run(run_async_server(), debug=True)
60
+ diff --git a/examples/server_sync.py b/examples/server_sync.py
61
+ --- a/examples/server_sync.py
62
+ +++ b/examples/server_sync.py
63
+ @@ -313,5 +313,5 @@
64
+
65
+
66
+ if __name__ == "__main__":
67
+ - server = run_sync_server(".")
68
+ + server = run_sync_server()
69
+ server.shutdown()
70
+
71
+ ```
72
+ """
73
+
74
+ # ds = load_dataset("rasdani/github-patches-10k-sample-sorted", split="train")
75
+ ds = load_dataset("rasdani/github-patches-decontaminated", split="train")
76
+
77
+
78
+ def prepend_line_numbers(file_content: str) -> str:
79
+ if not file_content:
80
+ return ""
81
+ lines = file_content.split('\n')
82
+ lines = [f"{i+1} {line}" for i, line in enumerate(lines)]
83
+ ret = '\n'.join(lines)
84
+ ret = ret.strip() + "\n"
85
+ return ret
86
+
87
+ def normalize_diff(diff_text: str) -> str:
88
+ diff_text = re.sub(r'(?m)^index [^\n]*\n', '', diff_text)
89
+ diff_text = re.sub(r'(?m)^(@@[^@]*@@).*', r'\1', diff_text)
90
+ diff_text = diff_text.strip() + "\n"
91
+ return diff_text
92
+
93
+ def filter_diff_by_files(diff: str, touched_files: set) -> str:
94
+ """Filter a git diff to only include changes for specific files."""
95
+ if not touched_files:
96
+ return diff
97
+
98
+ lines = diff.split('\n')
99
+ filtered_lines = []
100
+ include_section = False
101
+
102
+ for line in lines:
103
+ if line.startswith('diff --git'):
104
+ # Check if this file should be included
105
+ # Extract the file path from "diff --git a/path b/path"
106
+ match = re.match(r'diff --git a/(.*?) b/', line)
107
+ if match:
108
+ file_path = match.group(1)
109
+ include_section = file_path in touched_files
110
+ else:
111
+ include_section = False
112
+
113
+ if include_section:
114
+ filtered_lines.append(line)
115
+
116
+ return '\n'.join(filtered_lines)
117
+
118
+ def create_golden_diff(example):
119
+ before_paths = [b["path"] for b in example["before_files"]]
120
+ after_paths = [a["path"] for a in example["after_files"]]
121
+ touched_files = set(before_paths) | set(after_paths)
122
+ filtered_diff = filter_diff_by_files(example["pr_diff"], touched_files)
123
+ golden_diff = normalize_diff(filtered_diff)
124
+ for path in touched_files:
125
+ assert path in golden_diff, f"Path {path} not found in golden diff {golden_diff}"
126
+ verification_info_dict = {
127
+ "golden_diff": golden_diff,
128
+ "issue": example["issue"],
129
+ "before_files": example["before_files"],
130
+ "after_files": example["after_files"],
131
+ }
132
+ verification_info = json.dumps(verification_info_dict)
133
+ return {"golden_diff": golden_diff, "verification_info": verification_info}
134
+
135
+ def create_prompt(example):
136
+ golden_diff = example["golden_diff"]
137
+ issue = example["issue"]
138
+ before_files = example["before_files"]
139
+ file_context = [f"Path: `{x['path']}`\nContent:\n```\n{prepend_line_numbers(x['content'])}```" for x in before_files]
140
+ file_context = "\n\n".join(file_context)
141
+ prompt = PROMPT_TEMPLATE.format(issue=issue, file_context=file_context, golden_diff=golden_diff)
142
+ # print(prompt)
143
+ # print("="*100)
144
+ return {"prompt": prompt}
145
+
146
+
147
+
148
+ ds_up = ds.map(lambda x, idx: {"problem_id": f"gh_patches_debug_{idx}"}, with_indices=True)
149
+ ds_up = ds_up.map(lambda x: {"source": "rasdani/github-patches", "task_type": "git_diff"})
150
+
151
+ ds_up = ds_up.map(create_golden_diff, num_proc=10)
152
+ # example = ds_up[0]
153
+ # create_prompt(example)
154
+ ds_up = ds_up.map(create_prompt, num_proc=10)
155
+
156
+ ds_up = ds_up.select_columns(["problem_id", "source", "task_type", "in_source_id", "prompt", "golden_diff", "verification_info"])
157
+
158
+ # ds_up.push_to_hub("rasdani/github-patches-debug")
159
+ # ds_up.push_to_hub("rasdani/github-patches-debug-genesys")
160
+ ds_up = ds_up.shuffle(seed=42)
161
+ ds_up.push_to_hub("rasdani/github-patches-genesys")
162
+ ```