| 5 | from swebench.harness.docker_build import build_instance_images |
| 6 | |
| 7 | class SWEBench(BaseTask): |
| 8 | def __init__(self, logdir, split, _type="patch", **kwargs): |
| 9 | self.max_repetitions = kwargs.get("max_repetitions", 3) |
| 10 | self.task_template = """You need to identify the cause of the following github issue, collect the relevant information, and provide a solution. |
| 11 | Github Issue: ```{issue}```""" |
| 12 | |
| 13 | self.logdir = logdir |
| 14 | self.dataset = load_dataset("princeton-nlp/SWE-bench_Verified")[split] |
| 15 | |
| 16 | client = docker.from_env() |
| 17 | |
| 18 | successful, failed = build_instance_images( |
| 19 | client=client, |
| 20 | dataset=self.dataset, |
| 21 | force_rebuild=False, |
| 22 | max_workers=12, |
| 23 | ) |
| 24 | |
| 25 | self.images = {specs.instance_id: specs.instance_image_key for specs in successful} |
| 26 | self.dataset = self.dataset.filter(lambda x: x["instance_id"] in [specs.instance_id for specs in successful]) |
| 27 | self.setup_scripts = ["\n".join(["#!/bin/bash", "set -euxo pipefail"] + specs.env_script_list) + "\n" for specs in successful] |
| 28 | |
| 29 | |
| 30 | def construct_prompt(self, idx): |
| 31 | instance = self.dataset[idx] |
| 32 | return self.task_template.format(issue=instance["problem_statement"]) |
| 33 | |
| 34 | def __len__(self): |
| 35 | return len(self.dataset) |
| 36 | |
| 37 | def __getitem__(self, idx): |
| 38 | repo = self.dataset[idx]["repo"] |
| 39 | commit = self.dataset[idx]["base_commit"] |
| 40 | instance_id = self.dataset[idx]["instance_id"] |
| 41 | |
| 42 | repo_link = f"https://github.com/{repo}" |
| 43 | return repo_link, commit, instance_id, self.images[instance_id] |
| 44 | |
| 45 | def run(self, system, idx) -> Result: |
| 46 | prompt = self.construct_prompt(idx) |
| 47 | system.query_codebase(prompt) |
| 48 | prediction_patch = extract_patch(system.repo_dir) |
| 49 | return prediction_patch |
| 50 | |
| 51 | |
| 52 | def validate(self, proposed_patch, idx: int): |
| 53 | pass |
| 54 | |
| 55 | if __name__ == "__main__": |
| 56 | task = SWEBench("logs", "test") |
no outgoing calls
no test coverage detected