|
|
--- |
|
|
language: |
|
|
- en |
|
|
tags: |
|
|
- code |
|
|
- rust |
|
|
- payment-processing |
|
|
- hyperswitch |
|
|
- fintech |
|
|
- dataset |
|
|
- programming |
|
|
size_categories: |
|
|
- 10K<n<100K |
|
|
source_datasets: |
|
|
- hyperswitch |
|
|
task_categories: |
|
|
- text-generation |
|
|
--- |
|
|
|
|
|
# Hyperswitch Rust Codebase Dataset |
|
|
|
|
|
A comprehensive dataset extracted from the [Hyperswitch](https://github.com/juspay/hyperswitch) open-source payment processing platform, containing **16,731 code samples** across **37 modules** with **6.99M tokens** for training Rust code understanding and generation models. |
|
|
|
|
|
## ๐ Dataset Overview |
|
|
|
|
|
This dataset provides both **file-level** and **granular** code samples from Hyperswitch, a modern payment switch written in Rust. It's designed for training code models to understand payment processing patterns, Rust idioms, and large-scale system architecture. |
|
|
|
|
|
### Key Statistics |
|
|
- **Total Samples**: 16,731 |
|
|
- **Total Tokens**: 6,991,792 |
|
|
- **File-level Samples**: 2,120 complete files |
|
|
- **Granular Samples**: 14,611 extracted components |
|
|
- **Modules**: 37 distinct modules |
|
|
- **License**: Apache 2.0 |
|
|
|
|
|
## ๐๏ธ Dataset Structure |
|
|
|
|
|
### Sample Distribution by Type |
|
|
|
|
|
| Type | Count | Description | |
|
|
|------|-------|-------------| |
|
|
| **Struct Definitions** | 5,710 | Data structures and models | |
|
|
| **Implementation Blocks** | 4,296 | Method implementations | |
|
|
| **Function Signatures** | 4,121 | Function definitions | |
|
|
| **Full Files** | 1,666 | Complete source files | |
|
|
| **File Chunks** | 454 | Large file segments | |
|
|
| **Module Structures** | 261 | Module declarations | |
|
|
| **Trait Definitions** | 223 | Interface definitions | |
|
|
|
|
|
### File-level vs Granular Split |
|
|
- **File-level (2,120)**: Complete files with full context |
|
|
- **Granular (14,611)**: Extracted functions, structs, traits, and implementations |
|
|
|
|
|
## ๐๏ธ Module Coverage |
|
|
|
|
|
The dataset spans **37 modules** covering different aspects of payment processing: |
|
|
|
|
|
- `router` - Payment routing logic |
|
|
- `payment_methods` - Payment method handling |
|
|
- `hyperswitch_connectors` - Payment gateway connectors |
|
|
- `cards` - Card processing utilities |
|
|
- `api_models` - API request/response models |
|
|
- `diesel_models` - Database models |
|
|
- `storage_impl` - Data persistence layer |
|
|
- `redis_interface` - Caching layer |
|
|
- `currency_conversion` - Multi-currency support |
|
|
- `analytics` - Payment analytics |
|
|
- `events` - Event handling system |
|
|
- `scheduler` - Background job processing |
|
|
- `test_utils` - Testing utilities |
|
|
- `hsdev` - Development tools |
|
|
- `connector-template` - Connector scaffolding |
|
|
- `external_services` - Third-party integrations |
|
|
- `openapi` - API documentation |
|
|
- `euclid` - Routing engine |
|
|
- `smithy` - Code generation |
|
|
|
|
|
*[Complete list of 37 modules included in dataset]* |
|
|
|
|
|
## ๐ Data Format |
|
|
|
|
|
Each sample in `all_data.jsonl` contains: |
|
|
|
|
|
```json |
|
|
{ |
|
|
"text": "// Rust code content", |
|
|
"file_path": "relative/path/to/file.rs", |
|
|
"module": "module_name", |
|
|
"type": "struct_definition|function_signature|full_file|...", |
|
|
"tokens": 150, |
|
|
"metadata": { |
|
|
"functions": ["func1", "func2"], |
|
|
"structs": ["Struct1", "Struct2"], |
|
|
"traits": ["Trait1"], |
|
|
"dependencies": ["use statements"] |
|
|
} |
|
|
} |
|
|
``` |
|
|
|
|
|
## ๐ฏ Use Cases |
|
|
|
|
|
### Primary Applications |
|
|
- **Code Understanding**: Train models to explain Rust code patterns |
|
|
- **Code Generation**: Generate payment processing logic |
|
|
- **Documentation**: Automatic code documentation |
|
|
- **Code Review**: Assist in code quality assessment |
|
|
- **Developer Onboarding**: Help new developers understand codebase |
|
|
|
|
|
### Specific Domains |
|
|
- **Payment Processing**: Understanding financial transaction flows |
|
|
- **Rust Programming**: Learning Rust idioms and patterns |
|
|
- **Microservices Architecture**: Understanding distributed system patterns |
|
|
- **API Design**: Learning REST API patterns |
|
|
- **Database Integration**: Understanding ORM patterns |
|
|
|
|
|
## ๐ ๏ธ Dataset Creation |
|
|
|
|
|
### Extraction Process |
|
|
1. **Repository Analysis**: Scanned entire Hyperswitch codebase |
|
|
2. **File Filtering**: Included `.rs` files, excluded generated code |
|
|
3. **Granular Extraction**: Used regex patterns to extract: |
|
|
- Function definitions with context |
|
|
- Struct definitions with documentation |
|
|
- Trait definitions and implementations |
|
|
- Module declarations |
|
|
4. **Chunk Processing**: Large files split with 512-token overlap |
|
|
5. **Metadata Generation**: Extracted dependencies and cross-references |
|
|
|
|
|
### Quality Controls |
|
|
- **Syntax Validation**: All samples are valid Rust code |
|
|
- **Context Preservation**: Maintains import statements and dependencies |
|
|
- **Documentation Included**: Preserves `///` and `//!` comments |
|
|
- **Test Coverage**: Includes test files for usage patterns |
|
|
|
|
|
## ๐ Model Training |
|
|
|
|
|
### Recommended Usage |
|
|
- **Context Window**: 8,192 tokens (handles 95% of samples) |
|
|
- **Training Split**: 90% train, 10% validation |
|
|
- **Token Distribution**: Well-balanced across different code constructs |
|
|
- **Batch Size**: Adjust based on context window and hardware |
|
|
|
|
|
### Training Considerations |
|
|
- **Code Completion**: Use for next-token prediction |
|
|
- **Code Understanding**: Use for explanation tasks |
|
|
- **Fine-tuning**: Excellent for domain-specific adaptation |
|
|
- **Evaluation**: Test on payment processing concepts |
|
|
|
|
|
## ๐ Sample Examples |
|
|
|
|
|
### Struct Definition |
|
|
```rust |
|
|
/// Payment connector configuration |
|
|
#[derive(Debug, Clone, Serialize, Deserialize)] |
|
|
pub struct ConnectorConfig { |
|
|
pub connector_name: String, |
|
|
pub api_endpoint: Url, |
|
|
pub credentials: ConnectorCredentials, |
|
|
pub supported_payment_methods: Vec<PaymentMethod>, |
|
|
} |
|
|
``` |
|
|
|
|
|
### Function Signature |
|
|
```rust |
|
|
/// Process payment through selected connector |
|
|
pub async fn process_payment( |
|
|
state: &AppState, |
|
|
payment_data: PaymentData, |
|
|
connector: &dyn PaymentConnector, |
|
|
) -> RouterResult<PaymentResponse> |
|
|
``` |
|
|
|
|
|
### Implementation Block |
|
|
```rust |
|
|
impl PaymentConnector for StripeConnector { |
|
|
async fn authorize_payment( |
|
|
&self, |
|
|
request: PaymentAuthorizeRequest, |
|
|
) -> ConnectorResult<PaymentAuthorizeResponse> { |
|
|
// Implementation details... |
|
|
} |
|
|
} |
|
|
``` |
|
|
|
|
|
## ๐ Dataset Quality |
|
|
|
|
|
### Metrics |
|
|
- **Syntax Validity**: 100% (all samples compile) |
|
|
- **Documentation Coverage**: 85% have doc comments |
|
|
- **Test Coverage**: 15% are test files |
|
|
- **Average Tokens per Sample**: 418 tokens |
|
|
- **Context Completeness**: 95% have necessary imports |
|
|
|
|
|
### Validation |
|
|
- **Automated Testing**: All samples pass `cargo check` |
|
|
- **Manual Review**: Random sampling verified for quality |
|
|
- **Deduplication**: Identical code blocks removed |
|
|
- **Privacy**: No sensitive credentials or API keys |
|
|
|
|
|
## ๐ Getting Started |
|
|
|
|
|
### Download and Usage |
|
|
```python |
|
|
# Load dataset |
|
|
import json |
|
|
|
|
|
samples = [] |
|
|
with open('all_data.jsonl', 'r') as f: |
|
|
for line in f: |
|
|
samples.append(json.loads(line)) |
|
|
|
|
|
print(f"Loaded {len(samples)} samples") |
|
|
print(f"Sample types: {set(s['type'] for s in samples)}") |
|
|
``` |
|
|
|
|
|
### Training Example |
|
|
```python |
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM |
|
|
from datasets import Dataset |
|
|
|
|
|
# Load tokenizer |
|
|
tokenizer = AutoTokenizer.from_pretrained("Kwaipilot/KAT-Dev") |
|
|
|
|
|
# Prepare dataset |
|
|
def tokenize_function(examples): |
|
|
return tokenizer(examples["text"], truncation=True, max_length=8192) |
|
|
|
|
|
dataset = Dataset.from_list(samples) |
|
|
tokenized_dataset = dataset.map(tokenize_function, batched=True) |
|
|
``` |
|
|
|
|
|
## ๐ Acknowledgments |
|
|
|
|
|
- **Hyperswitch Team** for building an excellent open-source payment platform |
|
|
- **Rust Community** for creating robust tooling and documentation standards |
|
|
- **Juspay Technologies** for open-sourcing this valuable codebase |
|
|
|
|
|
## ๐ Citation |
|
|
|
|
|
```bibtex |
|
|
@dataset{HyperSwitch-Repo-CPT-Dataset, |
|
|
title={HyperSwitch-Repo-CPT-Dataset}, |
|
|
author={Aditya Narayan}, |
|
|
year={2024}, |
|
|
publisher={Hugging Face}, |
|
|
url={https://huggingface.co/datasets/AdityaNarayan/HyperSwitch-Repo-CPT-Dataset}, |
|
|
note={Extracted from https://github.com/juspay/hyperswitch} |
|
|
} |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
*This dataset is part of ongoing research into domain-specific code model training for financial technology applications.* |