rasdani's picture
Update README.md
25a0f96 verified
|
raw
history blame
4.42 kB
metadata
dataset_info:
  features:
    - name: in_source_id
      dtype: string
    - name: before_files
      list:
        - name: content
          dtype: string
        - name: path
          dtype: string
    - name: after_files
      list:
        - name: content
          dtype: string
        - name: path
          dtype: string
    - name: pr_diff
      dtype: string
    - name: issue
      dtype: string
    - name: golden_diff
      dtype: string
    - name: verification_info
      dtype: string
    - name: prompt
      dtype: string
  splits:
    - name: train
      num_bytes: 122417603
      num_examples: 1641
  download_size: 51102842
  dataset_size: 122417603
configs:
  - config_name: default
    data_files:
      - split: train
        path: data/train-*
import re
import json
from datasets import load_dataset

PROMPT_TEMPLATE = """\
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
{issue}
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
{file_context}
--- END FILES ---

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.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

"""

ds = load_dataset("rasdani/github-patches-10k-sample-sorted", split="train")

def prepend_line_numbers(file_content: str) -> str: lines = file_content.split('\n') lines = [f"{i+1} {line}" for i, line in enumerate(lines)] return '\n'.join(lines)

def normalize_diff(diff_text: str) -> str: diff_text = re.sub(r'(?m)^index [^\n]\n', '', diff_text) diff_text = re.sub(r'(?m)^(@@[^@]@@).*', r'\1', diff_text) diff_text = diff_text.strip() + "\n" return diff_text

def filter_diff_by_files(diff: str, touched_files: set) -> str: """Filter a git diff to only include changes for specific files.""" if not touched_files: return diff

lines = diff.split('\n')
filtered_lines = []
include_section = False

for line in lines:
    if line.startswith('diff --git'):
        # Check if this file should be included
        # Extract the file path from "diff --git a/path b/path"
        match = re.match(r'diff --git a/(.*?) b/', line)
        if match:
            file_path = match.group(1)
            include_section = file_path in touched_files
        else:
            include_section = False
    
    if include_section:
        filtered_lines.append(line)

return '\n'.join(filtered_lines)

def create_golden_diff(example): before_paths = [b["path"] for b in example["before_files"]] after_paths = [a["path"] for a in example["after_files"]] touched_files = set(before_paths) | set(after_paths) filtered_diff = filter_diff_by_files(example["pr_diff"], touched_files) golden_diff = normalize_diff(filtered_diff) for path in touched_files: assert path in golden_diff, f"Path {path} not found in golden diff {golden_diff}" verification_info = json.dumps({"golden_diff": golden_diff}) return {"golden_diff": golden_diff, "verification_info": verification_info}

def create_prompt(example): golden_diff = example["golden_diff"] issue = example["issue"] before_files = example["before_files"] file_context = [f"Path: {x['path']}\nContent:\n\n{prepend_line_numbers(x['content'])}" for x in before_files] file_context = "\n\n".join(file_context) prompt = PROMPT_TEMPLATE.format(issue=issue, file_context=file_context, golden_diff=golden_diff) # print(prompt) # print("="*100) return {"prompt": prompt}

ds_up = ds.map(create_golden_diff, num_proc=10)

example = ds_gen[-1]

create_prompt(example)

ds_up = ds_gen.map(create_prompt, num_proc=10) ds_up.push_to_hub("rasdani/github-patches-debug")