wei commited on
Commit
e70ecfd
·
1 Parent(s): 0d0ae89

docs: add readme

Browse files
Files changed (1) hide show
  1. README.md +386 -0
README.md CHANGED
@@ -1,3 +1,389 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ # SWEBenchV2
6
+
7
+ [![PyPI version](https://img.shields.io/pypi/v/swebenchv2.svg)](https://pypi.org/project/swebenchv2/)
8
+ [![python](https://img.shields.io/badge/-Python_3.10_%7C_3.11_%7C_3.12-blue?logo=python&logoColor=white)](https://github.com/pre-commit/pre-commit)
9
+ [![uv](https://img.shields.io/badge/-uv_dependency_management-2C5F2D?logo=python&logoColor=white)](https://docs.astral.sh/uv/)
10
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
11
+ [![tests](https://github.com/Mai0313/SWEBenchV2/actions/workflows/test.yml/badge.svg)](https://github.com/Mai0313/SWEBenchV2/actions/workflows/test.yml)
12
+ [![code-quality](https://github.com/Mai0313/SWEBenchV2/actions/workflows/code-quality-check.yml/badge.svg)](https://github.com/Mai0313/SWEBenchV2/actions/workflows/code-quality-check.yml)
13
+ [![license](https://img.shields.io/badge/License-MIT-green.svg?labelColor=gray)](https://github.com/Mai0313/SWEBenchV2/tree/master?tab=License-1-ov-file)
14
+ [![PRs](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Mai0313/SWEBenchV2/pulls)
15
+ [![contributors](https://img.shields.io/github/contributors/Mai0313/SWEBenchV2.svg)](https://github.com/Mai0313/SWEBenchV2/graphs/contributors)
16
+
17
+ **An innovative alternative to SWE-Bench that focuses on measuring how closely AI models match real developer coding patterns rather than binary correctness.**
18
+
19
+ **Other Languages**: [English](README.md) | [中文](README_cn.md)
20
+
21
+ ## 🚀 Overview
22
+
23
+ Traditional benchmarks like SWE-Bench test whether models can solve predefined problems correctly. SWEBenchV2 takes a different approach: it measures how similar an AI model's coding style and decisions are to those of experienced developers who have already reviewed and approved the code changes.
24
+
25
+ ### Core Philosophy
26
+
27
+ Instead of asking "Did the model get the right answer?", we ask "How closely does the model's approach match what experienced developers actually do?"
28
+
29
+ This approach assumes that merged pull requests represent consensus among experienced developers about the "right" way to implement changes. By comparing model outputs to these real-world solutions, we can evaluate not just correctness but also coding style, problem-solving approach, and adherence to project conventions.
30
+
31
+ ## 🎯 Key Features
32
+
33
+ - **🔍 Real-world Data**: Extracts training data from actual merged pull requests
34
+ - **📊 Pattern Matching**: Focuses on similarity to developer patterns rather than binary correctness
35
+ - **📋 Comprehensive Analysis**: Captures before/after code states, PR context, and metadata
36
+ - **🔗 GitHub Integration**: Seamlessly connects to any GitHub repository
37
+ - **⚡ High-Performance Async**: Multi-level concurrent processing with `asyncio.gather()` for maximum speed
38
+ - **🚦 Smart Rate Limiting**: Built-in GitHub API rate limit management with semaphore-based concurrency control
39
+ - **⚙️ Flexible Configuration**: Configurable extraction parameters for different use cases
40
+ - **📚 Comprehensive Documentation**: All functions include detailed Google-style docstrings with parameter types and return values
41
+
42
+ ## 📊 How It Works
43
+
44
+ 1. **Data Extraction**: Scans GitHub repositories for merged pull requests
45
+ 2. **Content Capture**: Records the before and after states of all modified files
46
+ 3. **Context Preservation**: Maintains PR titles, descriptions, and metadata
47
+ 4. **Dataset Generation**: Creates structured training data suitable for LLM evaluation
48
+ 5. **Benchmark Creation**: Provides question-context-answer triplets for model testing
49
+
50
+ ### Data Structure
51
+
52
+ Each extracted PR becomes a benchmark item with:
53
+
54
+ - **Question**: PR title and description (the problem to solve)
55
+ - **Context**: Before-state of modified files and filenames
56
+ - **Expected Answer**: After-state of modified files (the "correct" solution)
57
+
58
+ ## �️ Installation
59
+
60
+ ### Prerequisites
61
+
62
+ - Python 3.10 or higher
63
+ - [uv](https://github.com/astral-sh/uv) for dependency management
64
+ - GitHub API token (for accessing repositories)
65
+
66
+ ### Setup
67
+
68
+ 1. **Clone the repository:**
69
+
70
+ ```bash
71
+ git clone https://github.com/Mai0313/SWEBenchV2.git
72
+ cd SWEBenchV2
73
+ ```
74
+
75
+ 1. **Install dependencies:**
76
+
77
+ ```bash
78
+ uv sync
79
+ ```
80
+
81
+ 1. **Install as a package (for CLI usage):**
82
+
83
+ ```bash
84
+ uv pip install -e .
85
+ ```
86
+
87
+ 1. **Set up your GitHub token:**
88
+
89
+ ```bash
90
+ export GITHUB_TOKEN="your_github_token_here"
91
+ ```
92
+
93
+ ## 📖 Usage
94
+
95
+ ### CLI Usage (Recommended)
96
+
97
+ After installing the package, you can use the `swebenchv2` command directly:
98
+
99
+ ```bash
100
+ # Basic usage - extract PRs from a repository
101
+ swebenchv2 --repo_url="https://github.com/owner/repo"
102
+
103
+ # With custom parameters
104
+ swebenchv2 --repo_url="https://github.com/owner/repo" --max_page=5 --per_page=50
105
+
106
+ # Using synchronous mode
107
+ swebenchv2 main --repo_url="https://github.com/owner/repo"
108
+
109
+ # Using asynchronous mode (faster for large repositories)
110
+ swebenchv2 a_main --repo_url="https://github.com/owner/repo"
111
+
112
+ # The extracted data will be saved to ./data/{owner}/{repo}/log_{timestamp}.json
113
+ ```
114
+
115
+ ### Python Library Usage
116
+
117
+ ```python
118
+ from swebenchv2.datamodule.github import GitHubPRExtractor
119
+
120
+ # Initialize the extractor
121
+ extractor = GitHubPRExtractor(
122
+ repo_url="https://github.com/owner_name/repository_name",
123
+ max_page=10, # Limit pages to extract
124
+ per_page=50, # PRs per page
125
+ )
126
+
127
+ # Extract all PR data - now with comprehensive docstrings
128
+ result = extractor.extract_all_pr_data(save_json=True)
129
+ print(f"Extracted {result.total_prs} PRs from {result.repository}")
130
+
131
+ # All methods now include detailed documentation
132
+ # Check rate limits before extraction
133
+ rate_limit = extractor.get_rate_limit() # Returns RateLimit with remaining calls info
134
+ print(f"Remaining requests: {rate_limit.rate.remaining}")
135
+
136
+ # Get specific PR files with full documentation
137
+ merged_prs = extractor.get_merged_prs() # Returns list[PullRequest] with pagination
138
+ for pr in merged_prs[:3]:
139
+ files = extractor.get_pr_files(pr.number) # Returns list[FileData] for modified files
140
+ print(f"PR #{pr.number} modified {len(files)} files")
141
+ ```
142
+
143
+ ### Alternative Execution Methods
144
+
145
+ You can run the tool in several different ways:
146
+
147
+ ```bash
148
+ # Method 1: Direct CLI (after pip install -e .)
149
+ swebenchv2 --repo_url="https://github.com/owner/repo"
150
+
151
+ # Method 2: Using poethepoet task
152
+ poe main --repo_url="https://github.com/owner/repo"
153
+
154
+ # Method 3: Direct Python module execution
155
+ python src/swebenchv2/cli.py --repo_url="https://github.com/owner/repo"
156
+
157
+ # Method 4: Using uv run with cli entry point
158
+ uv run cli --repo_url="https://github.com/owner/repo"
159
+
160
+ # Method 5: Using uv run with swebenchv2 entry point
161
+ uv run swebenchv2 --repo_url="https://github.com/owner/repo"
162
+
163
+ # The extracted data will be saved to ./data/{owner}/{repo}/log_{timestamp}.json
164
+ ```
165
+
166
+ ### Advanced Configuration
167
+
168
+ ```python
169
+ extractor = GitHubPRExtractor(
170
+ repo_url="https://github.com/your_org/your_repo",
171
+ max_page=5, # Limit to first 5 pages
172
+ per_page=100, # 100 PRs per page
173
+ token="your_token", # Optional: set token directly
174
+ )
175
+
176
+ # Check rate limits before extraction
177
+ rate_limit = extractor.get_rate_limit()
178
+ print(f"Remaining requests: {rate_limit.rate.remaining}")
179
+
180
+ # Extract data for specific PRs
181
+ merged_prs = extractor.get_merged_prs()
182
+ for pr in merged_prs[:5]: # Process first 5 PRs
183
+ pr_data = extractor.extract_pr_data(pr)
184
+ print(f"Extracted data for PR #{pr.number}: {pr.title}")
185
+ ```
186
+
187
+ ### Asynchronous Usage
188
+
189
+ For better performance with large repositories, use the asynchronous version with optimized concurrent processing:
190
+
191
+ ```python
192
+ import asyncio
193
+ from swebenchv2.datamodule.github import AsyncGitHubPRExtractor
194
+
195
+
196
+ async def extract_data():
197
+ extractor = AsyncGitHubPRExtractor(
198
+ repo_url="https://github.com/your_org/your_repo", max_page=5, per_page=100
199
+ )
200
+
201
+ # Async extraction with multi-level concurrency
202
+ # - File content fetching: concurrent before/after retrieval
203
+ # - PR processing: concurrent file handling with semaphore control
204
+ # - Batch processing: concurrent PR extraction across repository
205
+ result = await extractor.extract_all_pr_data(save_json=True)
206
+ print(f"Extracted {result.total_prs} PRs with high-speed async processing")
207
+ return result
208
+
209
+
210
+ # Run async extraction
211
+ result = asyncio.run(extract_data())
212
+ ```
213
+
214
+ ### Performance Benefits
215
+
216
+ The async implementation provides significant performance improvements:
217
+
218
+ - **Concurrent File Processing**: Before/after content fetched simultaneously using `asyncio.gather()`
219
+ - **Parallel PR Handling**: Multiple PRs processed concurrently with semaphore-controlled limits
220
+ - **Batch API Optimization**: Reduced total execution time through intelligent parallel operations
221
+ - **Resource Efficiency**: Optimal utilization of network resources and API rate limits
222
+
223
+ Example performance improvements observed:
224
+
225
+ - Large repositories: 3-5x faster extraction compared to synchronous implementation
226
+ - Medium repositories: 2-3x speed improvement with concurrent processing
227
+ - Better API rate limit utilization through intelligent batching
228
+
229
+ ## 📁 Output Format
230
+
231
+ The extracted data is saved in JSON format with the following structure:
232
+
233
+ ```json
234
+ {
235
+ "repository": "owner/repo",
236
+ "extracted_at": "2024-01-01T12:00:00",
237
+ "total_prs": 100,
238
+ "prs": [
239
+ {
240
+ "pr_info": {
241
+ "number": 123,
242
+ "title": "Fix bug in authentication",
243
+ "body": "This PR fixes the authentication issue...",
244
+ "merged_at": "2024-01-01T10:00:00Z"
245
+ },
246
+ "question": "PR #123: Fix bug in authentication\nDescription:\nThis PR fixes...",
247
+ "files": [
248
+ {
249
+ "filename": "src/auth.py",
250
+ "status": "modified",
251
+ "before_edit": "# Original code...",
252
+ "after_edit": "# Modified code...",
253
+ "additions": 5,
254
+ "deletions": 2
255
+ }
256
+ ]
257
+ }
258
+ ]
259
+ }
260
+ ```
261
+
262
+ ## 🔧 Configuration
263
+
264
+ ### Environment Variables
265
+
266
+ | Variable | Description | Default |
267
+ | --------------------- | --------------------- | --------------------------------- |
268
+ | `GITHUB_TOKEN` | GitHub API token | None (required for private repos) |
269
+ | `GITHUB_API_BASE_URL` | Custom GitHub API URL | `https://api.github.com` |
270
+
271
+ ### Rate Limiting
272
+
273
+ The tool automatically handles GitHub API rate limits:
274
+
275
+ - 🔍 Monitors remaining requests
276
+ - ⏳ Automatically waits when limits are hit
277
+ - 📝 Provides informative logging about rate limit status
278
+
279
+ ## 🤖 Using with LLMs
280
+
281
+ The extracted data is designed to work seamlessly with language models:
282
+
283
+ ```python
284
+ # Example: Testing a model against extracted data
285
+ for pr_data in result.prs:
286
+ question = pr_data.question
287
+ context = {"files": {file.filename: file.before_edit for file in pr_data.files}}
288
+ expected_answer = {file.filename: file.after_edit for file in pr_data.files}
289
+
290
+ # Send to your LLM and compare similarity
291
+ model_response = your_llm.generate(question, context)
292
+ similarity_score = calculate_similarity(model_response, expected_answer)
293
+ ```
294
+
295
+ ## 🗂️ Project Structure
296
+
297
+ ```
298
+ ├── src/
299
+ │ └── swebenchv2/
300
+ │ ├── cli.py # CLI interface with documented entry points
301
+ │ ├── datamodule/
302
+ │ │ └── github.py # Main extraction logic with comprehensive docstrings
303
+ │ └── typings/
304
+ │ ├── models.py # Data models with documented save methods
305
+ │ ├── prs.py # Pull request types and enums
306
+ │ └── limit.py # Rate limit handling with status checking
307
+ ├── tests/ # Comprehensive test suite
308
+ ├── data/ # Output directory for extracted data
309
+ ├── pyproject.toml # Project configuration with CLI entry points
310
+ └── README.md # This file
311
+ ```
312
+
313
+ ### Key Functions Documentation
314
+
315
+ All core functions now include comprehensive Google-style docstrings:
316
+
317
+ **CLI Functions (`cli.py`)**:
318
+
319
+ - `SWEBench.main()` - Synchronous PR extraction with full documentation
320
+ - `SWEBench.a_main()` - Asynchronous PR extraction with performance notes
321
+ - `SWEBench.__call__()` - Callable interface documentation
322
+ - `main()` - CLI entry point with Fire integration details
323
+
324
+ **GitHub Integration (`github.py`)**:
325
+
326
+ - `GitHubPRExtractor.get_rate_limit()` - Rate limit checking with return type info
327
+ - `GitHubPRExtractor.get_merged_prs()` - PR fetching with pagination details
328
+ - `GitHubPRExtractor.get_pr_files()` - File extraction with metadata handling
329
+ - `GitHubPRExtractor.get_file_content()` - Content retrieval with SHA handling
330
+ - `GitHubPRExtractor.extract_pr_data()` - Single PR processing documentation
331
+ - `GitHubPRExtractor.extract_all_pr_data()` - Complete extraction orchestration
332
+
333
+ **Async Versions** - All async methods include concurrency and performance documentation
334
+
335
+ **Data Models (`models.py`)**:
336
+
337
+ - `ExtractionResult.save_log()` - JSON export with timestamp organization
338
+ - `ExtractionResult.a_save_log()` - Async file operations documentation
339
+
340
+ **Rate Limiting (`limit.py`)**:
341
+
342
+ - `RateLimit.is_rate_limited()` - API quota checking with boolean logic
343
+
344
+ ## 🔬 Evaluation Methodology
345
+
346
+ Unlike traditional benchmarks that focus on binary correctness, SWEBenchV2 evaluates:
347
+
348
+ 1. **Code Similarity**: How similar is the generated code to the approved solution?
349
+ 2. **Style Consistency**: Does the model follow the project's coding conventions?
350
+ 3. **Problem-solving Approach**: Does the model tackle problems the same way experienced developers do?
351
+ 4. **Contextual Awareness**: Does the model properly consider existing codebase patterns?
352
+
353
+ ## 🤝 Contributing
354
+
355
+ We welcome contributions! Here's how you can help:
356
+
357
+ 1. **Fork the repository**
358
+ 2. **Create a feature branch**: `git checkout -b feature-name`
359
+ 3. **Make your changes with tests**
360
+ 4. **Submit a pull request**
361
+
362
+ Please see our [Contributing Guidelines](CONTRIBUTING) for more details.
363
+
364
+ ## � Use Cases
365
+
366
+ - **Model Evaluation**: Assess how well AI models match real developer patterns
367
+ - **Training Data Generation**: Create realistic coding datasets from real repositories
368
+ - **Code Style Analysis**: Study coding patterns across different projects
369
+ - **Developer Behavior Research**: Analyze how experienced developers solve problems
370
+
371
+ ## � Acknowledgments
372
+
373
+ - Inspired by the original [SWE-Bench](https://www.swebench.com/) project
374
+ - Built on the principle that real developer consensus represents quality standards
375
+ - Designed for the era of AI-assisted software development
376
+
377
+ ## 📄 License
378
+
379
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
380
+
381
+ ---
382
+
383
+ <div align="center">
384
+
385
+ **Made with ❤️ for the AI and software development community**
386
+
387
+ [Report Bug](https://github.com/Mai0313/SWEBenchV2/issues) • [Request Feature](https://github.com/Mai0313/SWEBenchV2/issues) • [Documentation](https://mai0313.github.io/SWEBenchV2/)
388
+
389
+ </div>