Update README.md
Browse files
README.md
CHANGED
|
@@ -42,13 +42,57 @@ import re
|
|
| 42 |
import json
|
| 43 |
from datasets import load_dataset
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
ds = load_dataset("rasdani/github-patches-10k-sample-sorted", split="train")
|
| 47 |
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
def normalize_diff(diff_text: str) -> str:
|
| 50 |
diff_text = re.sub(r'(?m)^index [^\n]*\n', '', diff_text)
|
| 51 |
diff_text = re.sub(r'(?m)^(@@[^@]*@@).*', r'\1', diff_text)
|
|
|
|
| 52 |
return diff_text
|
| 53 |
|
| 54 |
def filter_diff_by_files(diff: str, touched_files: set) -> str:
|
|
@@ -87,7 +131,24 @@ def create_golden_diff(example):
|
|
| 87 |
verification_info = json.dumps({"golden_diff": golden_diff})
|
| 88 |
return {"golden_diff": golden_diff, "verification_info": verification_info}
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
ds_gen = ds.map(create_golden_diff, num_proc=10)
|
| 92 |
-
ds_gen.push_to_hub("rasdani/github-patches-genesys-debug")
|
| 93 |
```
|
|
|
|
| 42 |
import json
|
| 43 |
from datasets import load_dataset
|
| 44 |
|
| 45 |
+
PROMPT_TEMPLATE = """\
|
| 46 |
+
We are currently solving the following issue within our repository. Here is the issue text:
|
| 47 |
+
--- BEGIN ISSUE ---
|
| 48 |
+
{issue}
|
| 49 |
+
--- END ISSUE ---
|
| 50 |
+
|
| 51 |
+
Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
|
| 52 |
+
--- BEGIN FILES ---
|
| 53 |
+
{file_context}
|
| 54 |
+
--- END FILES ---
|
| 55 |
+
|
| 56 |
+
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.
|
| 57 |
+
|
| 58 |
+
Here is an example:
|
| 59 |
+
|
| 60 |
+
```diff
|
| 61 |
+
diff --git a/examples/server_async.py b/examples/server_async.py
|
| 62 |
+
--- a/examples/server_async.py
|
| 63 |
+
+++ b/examples/server_async.py
|
| 64 |
+
@@ -313,4 +313,4 @@
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
- asyncio.run(run_async_server("."), debug=True)
|
| 69 |
+
+ asyncio.run(run_async_server(), debug=True)
|
| 70 |
+
diff --git a/examples/server_sync.py b/examples/server_sync.py
|
| 71 |
+
--- a/examples/server_sync.py
|
| 72 |
+
+++ b/examples/server_sync.py
|
| 73 |
+
@@ -313,5 +313,5 @@
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if __name__ == "__main__":
|
| 77 |
+
- server = run_sync_server(".")
|
| 78 |
+
+ server = run_sync_server()
|
| 79 |
+
server.shutdown()
|
| 80 |
+
|
| 81 |
+
```
|
| 82 |
+
"""
|
| 83 |
|
| 84 |
ds = load_dataset("rasdani/github-patches-10k-sample-sorted", split="train")
|
| 85 |
|
| 86 |
|
| 87 |
+
def prepend_line_numbers(file_content: str) -> str:
|
| 88 |
+
lines = file_content.split('\n')
|
| 89 |
+
lines = [f"{i+1} {line}" for i, line in enumerate(lines)]
|
| 90 |
+
return '\n'.join(lines)
|
| 91 |
+
|
| 92 |
def normalize_diff(diff_text: str) -> str:
|
| 93 |
diff_text = re.sub(r'(?m)^index [^\n]*\n', '', diff_text)
|
| 94 |
diff_text = re.sub(r'(?m)^(@@[^@]*@@).*', r'\1', diff_text)
|
| 95 |
+
diff_text = diff_text.strip() + "\n"
|
| 96 |
return diff_text
|
| 97 |
|
| 98 |
def filter_diff_by_files(diff: str, touched_files: set) -> str:
|
|
|
|
| 131 |
verification_info = json.dumps({"golden_diff": golden_diff})
|
| 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 |
+
|
| 148 |
+
ds_up = ds.map(create_golden_diff, num_proc=10)
|
| 149 |
+
# example = ds_gen[-1]
|
| 150 |
+
# create_prompt(example)
|
| 151 |
+
ds_up = ds_gen.map(create_prompt, num_proc=10)
|
| 152 |
+
ds_up.push_to_hub("rasdani/github-patches-debug")
|
| 153 |
|
|
|
|
|
|
|
| 154 |
```
|