Spaces:
Sleeping
Sleeping
gary-boon
Claude
commited on
Commit
·
ae9e159
1
Parent(s):
1d23728
Fix SWE-bench service to gracefully handle dataset loading failures
Browse files- Add fallback to mock data when HuggingFace dataset loading fails
- Improve error handling for deployment environments
- Add detailed mock problem statements for better testing
- Fix initialization errors on HuggingFace Spaces
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
- backend/swe_bench_service.py +96 -26
backend/swe_bench_service.py
CHANGED
|
@@ -94,6 +94,69 @@ class SWEBenchService:
|
|
| 94 |
self.dataset_loaded = False
|
| 95 |
self.metrics_cache: Dict[str, Any] = {}
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
async def load_dataset(self, dataset_name: str = "princeton-nlp/SWE-bench_Lite"):
|
| 98 |
"""Load SWE-bench dataset from Hugging Face"""
|
| 99 |
try:
|
|
@@ -101,38 +164,45 @@ class SWEBenchService:
|
|
| 101 |
|
| 102 |
logger.info(f"Loading SWE-bench dataset: {dataset_name}")
|
| 103 |
|
| 104 |
-
# Load the dataset
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
# Initialize metrics cache
|
| 128 |
self._update_metrics_cache()
|
| 129 |
|
| 130 |
except ImportError:
|
| 131 |
-
logger.error("datasets library not installed.
|
| 132 |
-
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
-
logger.error(f"Failed to load SWE-bench dataset: {e}")
|
| 135 |
-
|
|
|
|
| 136 |
|
| 137 |
def get_tasks(
|
| 138 |
self,
|
|
|
|
| 94 |
self.dataset_loaded = False
|
| 95 |
self.metrics_cache: Dict[str, Any] = {}
|
| 96 |
|
| 97 |
+
def _load_mock_tasks(self):
|
| 98 |
+
"""Load mock tasks when dataset isn't available"""
|
| 99 |
+
repos = [
|
| 100 |
+
"astropy/astropy", "django/django", "matplotlib/matplotlib",
|
| 101 |
+
"pandas-dev/pandas", "pytest-dev/pytest", "scikit-learn/scikit-learn"
|
| 102 |
+
]
|
| 103 |
+
|
| 104 |
+
statements = [
|
| 105 |
+
"""Modeling's `separability_matrix` does not compute separability correctly for nested CompoundModels
|
| 106 |
+
|
| 107 |
+
Consider the following model:
|
| 108 |
+
|
| 109 |
+
```python
|
| 110 |
+
from astropy.modeling import models as m
|
| 111 |
+
from astropy.modeling.separable import separable_matrix
|
| 112 |
+
|
| 113 |
+
cm = m.Linear1D(10) & m.Linear1D(5)
|
| 114 |
+
```
|
| 115 |
+
|
| 116 |
+
It's separability matrix as you might expect is a diagonal:
|
| 117 |
+
|
| 118 |
+
```python
|
| 119 |
+
>>> separability_matrix(cm)
|
| 120 |
+
array([[ True, False],
|
| 121 |
+
[False, True]])
|
| 122 |
+
```""",
|
| 123 |
+
"""Please support header rows in RestructuredText output
|
| 124 |
+
|
| 125 |
+
### Description
|
| 126 |
+
It would be great if the RestructuredText output could have header rows for tables, similar to what MySQL does for pipe formatting.
|
| 127 |
+
|
| 128 |
+
### Expected behavior
|
| 129 |
+
According to the documentation for MyST parsers, the docutils RST table expects the first row to be treated as a header row.
|
| 130 |
+
|
| 131 |
+
### Actual behavior
|
| 132 |
+
The RST output treats the first row as a regular data row and doesn't mark it as a header.""",
|
| 133 |
+
"""Issue when parsing empty lists/arrays in configuration
|
| 134 |
+
|
| 135 |
+
When attempting to parse empty lists or arrays from configuration files, the parser incorrectly raises a ValueError instead of returning an empty list.
|
| 136 |
+
|
| 137 |
+
```python
|
| 138 |
+
>>> config.parse_list("[]")
|
| 139 |
+
ValueError: invalid literal for int() with base 10: '[]'
|
| 140 |
+
```
|
| 141 |
+
|
| 142 |
+
Expected behavior: Should return an empty list []"""
|
| 143 |
+
]
|
| 144 |
+
|
| 145 |
+
for i in range(100): # Create 100 mock tasks
|
| 146 |
+
repo = repos[i % len(repos)]
|
| 147 |
+
task = SWEBenchTask(
|
| 148 |
+
instance_id=f"{repo.split('/')[1]}__{i+11000}",
|
| 149 |
+
repo=repo,
|
| 150 |
+
problem_statement=statements[i % len(statements)],
|
| 151 |
+
base_commit=f"commit_{i:04d}",
|
| 152 |
+
patch="# Mock patch\n+ line added\n- line removed",
|
| 153 |
+
FAIL_TO_PASS=["test_1", "test_2"] if i % 2 == 0 else ["test_a"],
|
| 154 |
+
PASS_TO_PASS=["test_pass_1", "test_pass_2"]
|
| 155 |
+
)
|
| 156 |
+
self.tasks[task.instance_id] = task
|
| 157 |
+
|
| 158 |
+
logger.info(f"Loaded {len(self.tasks)} mock SWE-bench tasks")
|
| 159 |
+
|
| 160 |
async def load_dataset(self, dataset_name: str = "princeton-nlp/SWE-bench_Lite"):
|
| 161 |
"""Load SWE-bench dataset from Hugging Face"""
|
| 162 |
try:
|
|
|
|
| 164 |
|
| 165 |
logger.info(f"Loading SWE-bench dataset: {dataset_name}")
|
| 166 |
|
| 167 |
+
# Load the dataset with error handling
|
| 168 |
+
try:
|
| 169 |
+
dataset = load_dataset(dataset_name, split='test')
|
| 170 |
+
|
| 171 |
+
# Convert to our task format
|
| 172 |
+
for item in dataset:
|
| 173 |
+
task = SWEBenchTask(
|
| 174 |
+
instance_id=item['instance_id'],
|
| 175 |
+
repo=item['repo'],
|
| 176 |
+
problem_statement=item['problem_statement'],
|
| 177 |
+
base_commit=item['base_commit'],
|
| 178 |
+
patch=item.get('patch'),
|
| 179 |
+
test_patch=item.get('test_patch'),
|
| 180 |
+
hints_text=item.get('hints_text'),
|
| 181 |
+
created_at=item.get('created_at'),
|
| 182 |
+
version=item.get('version'),
|
| 183 |
+
FAIL_TO_PASS=item.get('FAIL_TO_PASS'),
|
| 184 |
+
PASS_TO_PASS=item.get('PASS_TO_PASS')
|
| 185 |
+
)
|
| 186 |
+
self.tasks[task.instance_id] = task
|
| 187 |
+
|
| 188 |
+
self.dataset_loaded = True
|
| 189 |
+
logger.info(f"Loaded {len(self.tasks)} SWE-bench tasks")
|
| 190 |
+
except Exception as dataset_error:
|
| 191 |
+
logger.warning(f"Could not load full dataset, using mock data: {dataset_error}")
|
| 192 |
+
self._load_mock_tasks()
|
| 193 |
+
self.dataset_loaded = True
|
| 194 |
|
| 195 |
# Initialize metrics cache
|
| 196 |
self._update_metrics_cache()
|
| 197 |
|
| 198 |
except ImportError:
|
| 199 |
+
logger.error("datasets library not installed. Using mock data instead")
|
| 200 |
+
self._load_mock_tasks()
|
| 201 |
+
self.dataset_loaded = True
|
| 202 |
except Exception as e:
|
| 203 |
+
logger.error(f"Failed to load SWE-bench dataset, using mock: {e}")
|
| 204 |
+
self._load_mock_tasks()
|
| 205 |
+
self.dataset_loaded = True
|
| 206 |
|
| 207 |
def get_tasks(
|
| 208 |
self,
|