Update README.md
Browse files
README.md
CHANGED
@@ -27,3 +27,133 @@ 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 |
+
|
76 |
+
|
77 |
+
def prepend_line_numbers(file_content: str) -> str:
|
78 |
+
if not file_content:
|
79 |
+
return ""
|
80 |
+
lines = file_content.split('\n')
|
81 |
+
lines = [f"{i+1} {line}" for i, line in enumerate(lines)]
|
82 |
+
ret = '\n'.join(lines)
|
83 |
+
ret = ret.strip() + "\n"
|
84 |
+
return ret
|
85 |
+
|
86 |
+
def normalize_diff(diff_text: str) -> str:
|
87 |
+
diff_text = re.sub(r'(?m)^index [^\n]*\n', '', diff_text)
|
88 |
+
diff_text = re.sub(r'(?m)^(@@[^@]*@@).*', r'\1', diff_text)
|
89 |
+
diff_text = diff_text.strip() + "\n"
|
90 |
+
return diff_text
|
91 |
+
|
92 |
+
def filter_diff_by_files(diff: str, touched_files: set) -> str:
|
93 |
+
"""Filter a git diff to only include changes for specific files."""
|
94 |
+
if not touched_files:
|
95 |
+
return diff
|
96 |
+
|
97 |
+
lines = diff.split('\n')
|
98 |
+
filtered_lines = []
|
99 |
+
include_section = False
|
100 |
+
|
101 |
+
for line in lines:
|
102 |
+
if line.startswith('diff --git'):
|
103 |
+
# Check if this file should be included
|
104 |
+
# Extract the file path from "diff --git a/path b/path"
|
105 |
+
match = re.match(r'diff --git a/(.*?) b/', line)
|
106 |
+
if match:
|
107 |
+
file_path = match.group(1)
|
108 |
+
include_section = file_path in touched_files
|
109 |
+
else:
|
110 |
+
include_section = False
|
111 |
+
|
112 |
+
if include_section:
|
113 |
+
filtered_lines.append(line)
|
114 |
+
|
115 |
+
return '\n'.join(filtered_lines)
|
116 |
+
|
117 |
+
def create_golden_diff(example):
|
118 |
+
before_paths = [b["path"] for b in example["before_files"]]
|
119 |
+
after_paths = [a["path"] for a in example["after_files"]]
|
120 |
+
touched_files = set(before_paths) | set(after_paths)
|
121 |
+
filtered_diff = filter_diff_by_files(example["pr_diff"], touched_files)
|
122 |
+
golden_diff = normalize_diff(filtered_diff)
|
123 |
+
for path in touched_files:
|
124 |
+
assert path in golden_diff, f"Path {path} not found in golden diff {golden_diff}"
|
125 |
+
verification_info_dict = {
|
126 |
+
"golden_diff": golden_diff,
|
127 |
+
"issue": example["issue"],
|
128 |
+
"before_files": example["before_files"],
|
129 |
+
"after_files": example["after_files"],
|
130 |
+
}
|
131 |
+
verification_info = json.dumps(verification_info_dict)
|
132 |
+
return {"golden_diff": golden_diff, "verification_info": verification_info}
|
133 |
+
|
134 |
+
def create_prompt(example):
|
135 |
+
golden_diff = example["golden_diff"]
|
136 |
+
issue = example["issue"]
|
137 |
+
before_files = example["before_files"]
|
138 |
+
file_context = [f"Path: `{x['path']}`\nContent:\n```\n{prepend_line_numbers(x['content'])}```" for x in before_files]
|
139 |
+
file_context = "\n\n".join(file_context)
|
140 |
+
prompt = PROMPT_TEMPLATE.format(issue=issue, file_context=file_context, golden_diff=golden_diff)
|
141 |
+
print(prompt)
|
142 |
+
print("="*100)
|
143 |
+
return {"prompt": prompt}
|
144 |
+
|
145 |
+
|
146 |
+
|
147 |
+
ds_up = ds.map(lambda x, idx: {"problem_id": f"gh_patches_debug_{idx}"}, with_indices=True)
|
148 |
+
ds_up = ds_up.map(lambda x: {"source": "rasdani/github-patches", "task_type": "git_diff"})
|
149 |
+
|
150 |
+
ds_up = ds_up.map(create_golden_diff, num_proc=10)
|
151 |
+
# example = ds_up[0]
|
152 |
+
# create_prompt(example)
|
153 |
+
ds_up = ds_up.map(create_prompt, num_proc=10)
|
154 |
+
|
155 |
+
ds_up = ds_up.select_columns(["problem_id", "source", "task_type", "in_source_id", "prompt", "golden_diff", "verification_info"])
|
156 |
+
|
157 |
+
# ds_up.push_to_hub("rasdani/github-patches-debug")
|
158 |
+
ds_up.push_to_hub("rasdani/github-patches-debug-genesys")
|
159 |
+
```
|