Skip to content

chore: add swe bench example fetcher #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/codegen/extensions/langchain/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""Utilities for working with language models and datasets."""

from dataclasses import dataclass
from typing import Optional

import requests


@dataclass
class SweBenchExample:
"""A single example from the SWE-bench dataset."""

repo: str
instance_id: str
base_commit: str
patch: str
test_patch: str
problem_statement: str
hints_text: Optional[str]
created_at: str
version: str
fail_to_pass: str
pass_to_pass: Optional[str]
environment_setup_commit: Optional[str]


def get_swe_bench_examples() -> list[SweBenchExample]:
"""Fetch examples from the SWE-bench dataset.

Returns:
List of SweBenchExample objects

Raises:
requests.RequestException: If the API request fails
"""
url = "https://datasets-server.huggingface.co/rows"
params = {
"dataset": "princeton-nlp/SWE-bench",
"config": "default",
"split": "dev",
"offset": 0,
"length": 100,
}

response = requests.get(url, params=params)

Check failure on line 45 in src/codegen/extensions/langchain/utils.py

View workflow job for this annotation

GitHub Actions / mypy

error: Argument "params" to "get" has incompatible type "dict[str, object]"; expected "SupportsItems[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None] | tuple[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None] | Iterable[tuple[str | bytes | int | float, str | bytes | int | float | Iterable[str | bytes | int | float] | None]] | str | bytes | None" [arg-type]
response.raise_for_status()
data = response.json()

examples = []
for row in data["rows"]:
example = SweBenchExample(
repo=row["row"]["repo"],
instance_id=row["row"]["instance_id"],
base_commit=row["row"]["base_commit"],
patch=row["row"]["patch"],
test_patch=row["row"]["test_patch"],
problem_statement=row["row"]["problem_statement"],
hints_text=row["row"].get("hints_text"),
created_at=row["row"]["created_at"],
version=row["row"]["version"],
fail_to_pass=row["row"]["FAIL_TO_PASS"],
pass_to_pass=row["row"].get("PASS_TO_PASS"),
environment_setup_commit=row["row"].get("environment_setup_commit"),
)
examples.append(example)

return examples
Loading