Skip to content

Commit 37ecd0e

Browse files
committed
Initial commit: buffdata AI training data optimizer with Gemini API
0 parents  commit 37ecd0e

33 files changed

Lines changed: 2273 additions & 0 deletions

.env.example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Gemini API Key (Required for Gemini API calls)
2+
GEMINI_API_KEY=your_gemini_api_key_here
3+
4+
# Optional Default Configurations
5+
BUFFDATA_DEFAULT_MODEL=gemini-3.7-flash
6+
BUFFDATA_EMBEDDING_MODEL=text-embedding-004
7+
BUFFDATA_CONCURRENCY=10
8+
BUFFDATA_MAX_RPM=60

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.venv/
2+
__pycache__/
3+
*.pyc
4+
*.pyo
5+
*.pyd
6+
.pytest_cache/
7+
.coverage
8+
htmlcov/
9+
dist/
10+
build/
11+
*.egg-info/
12+
.env
13+
checkpoints/
14+
outputs/
15+
*.parquet
16+
*.jsonl
17+
!examples/*.jsonl

=65.0,

Whitespace-only changes.

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# 🚀 `buffdata`
2+
3+
**AI Training Data Optimizer powered by Google Gemini API**
4+
5+
`buffdata` is a high-throughput, modular CLI and Python framework designed to optimize, score, refine, evolve, and deduplicate AI datasets for Supervised Fine-Tuning (SFT), Pre-training, and Preference Tuning (DPO / RLHF) using state-of-the-art Google Gemini models (`gemini-3.7-flash`, `gemini-3.5-flash-lite`, and `text-embedding-004`).
6+
7+
---
8+
9+
## 🌟 Key Features
10+
11+
- 🎯 **LLM-as-a-Judge Quality Scoring**: Multi-dimensional evaluation (Clarity, Factual Accuracy, Reasoning Depth, Instruction Adherence, Safety) with structured Pydantic schemas.
12+
- 🧹 **Deep Data Refinement & Cleansing**: Eliminates AI conversational boilerplate (*"As an AI..."*, *"Certainly!"*), expands chain-of-thought reasoning, and fixes syntax/markdown errors.
13+
- 🧬 **Evol-Instruct Data Synthesis**: Complexifies datasets through reasoning deepening, constraint addition, concretization, and domain expansion.
14+
- ⚖️ **Automated DPO Preference Builder**: Automatically synthesizes high-contrast `chosen` vs. `rejected` pairs with explicit defect explanations.
15+
- 🔍 **Semantic & Lexical Deduplication**: Exact SHA-256 hash, MinHash n-gram LSH, and Gemini dense embedding similarity deduplication.
16+
-**Async High-Throughput Engine**: Token-bucket rate limiting (RPM/TPM), concurrency control, and auto-resuming checkpoints.
17+
- 📊 **Interactive HTML & Markdown Reports**: Rich visual analytics with score distribution charts, identified issue breakdown, and Before vs. After diff viewers.
18+
19+
---
20+
21+
## 📦 Installation
22+
23+
```bash
24+
# Clone the repository and navigate to directory
25+
cd ~/projects/buffdata
26+
27+
# Create virtual environment
28+
python3 -m venv .venv
29+
source .venv/bin/activate
30+
31+
# Install in editable mode
32+
pip install -e ".[dev]"
33+
```
34+
35+
---
36+
37+
## 🔑 Setup API Key
38+
39+
Set your Google Gemini API key:
40+
41+
```bash
42+
export GEMINI_API_KEY="your-gemini-api-key"
43+
```
44+
45+
Or create a `.env` file in the project directory:
46+
47+
```env
48+
GEMINI_API_KEY=your-gemini-api-key
49+
BUFFDATA_DEFAULT_MODEL=gemini-3.7-flash
50+
```
51+
52+
---
53+
54+
## 💻 CLI Quickstart
55+
56+
### 1. Score & Filter Dataset
57+
```bash
58+
buffdata score examples/alpaca_sample.jsonl -o filtered.jsonl --min-score 7.5 --filter
59+
```
60+
61+
### 2. Refine & Elevate Quality
62+
```bash
63+
buffdata refine examples/alpaca_sample.jsonl -o refined.jsonl --mode all
64+
```
65+
66+
### 3. Evolve Reasoning Complexity (Evol-Instruct)
67+
```bash
68+
buffdata evolve examples/alpaca_sample.jsonl -o evolved.jsonl --strategy deepen_reasoning
69+
```
70+
71+
### 4. Build DPO / RLHF Preference Pairs
72+
```bash
73+
buffdata dpo examples/alpaca_sample.jsonl -o dpo_dataset.jsonl
74+
```
75+
76+
### 5. Deduplicate
77+
```bash
78+
buffdata dedup examples/alpaca_sample.jsonl -o deduped.jsonl --method minhash --threshold 0.85
79+
```
80+
81+
### 6. Run Full Multi-Stage Pipeline
82+
```bash
83+
buffdata pipeline examples/pipeline_config.yaml -i examples/alpaca_sample.jsonl -o optimized.jsonl
84+
```
85+
86+
### 7. View Stats & Generate HTML Audit Report
87+
```bash
88+
# Print summary to terminal
89+
buffdata stats examples/alpaca_sample.jsonl
90+
91+
# Generate interactive HTML report
92+
buffdata report examples/alpaca_sample.jsonl -o audit_report.html
93+
```
94+
95+
---
96+
97+
## 🐍 Python SDK Example
98+
99+
```python
100+
from buffdata import GeminiClient, QualityScorer, DataRefiner, read_dataset, write_dataset
101+
102+
# Load dataset
103+
items = read_dataset("examples/alpaca_sample.jsonl")
104+
105+
# Initialize client and optimizer
106+
client = GeminiClient(default_model="gemini-3.7-flash")
107+
refiner = DataRefiner(client=client)
108+
109+
# Refine batch asynchronously
110+
import asyncio
111+
refined_items = asyncio.run(refiner.refine_batch_async(items, mode="all"))
112+
113+
# Save refined dataset
114+
write_dataset(refined_items, "refined_output.jsonl")
115+
```
116+
117+
---
118+
119+
## 🧪 Running Tests
120+
121+
```bash
122+
pytest tests/ -v
123+
```
124+
125+
---
126+
127+
## 📄 License
128+
MIT License.

buffdata/__init__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
buffdata: AI Training Data Optimizer powered by Google Gemini API.
3+
"""
4+
5+
__version__ = "0.1.0"
6+
7+
from buffdata.models.schemas import (
8+
DatasetItem,
9+
DatasetFormat,
10+
ChatMessage,
11+
QualityScore,
12+
RefinementResult,
13+
EvolutionResult,
14+
PreferenceResult,
15+
PipelineConfig,
16+
)
17+
from buffdata.engine.client import GeminiClient
18+
from buffdata.optimizers.scorer import QualityScorer, FastRuleFilter
19+
from buffdata.optimizers.refiner import DataRefiner
20+
from buffdata.optimizers.evolver import DataEvolver
21+
from buffdata.optimizers.preference import PreferenceBuilder
22+
from buffdata.optimizers.dedup import Deduplicator
23+
from buffdata.report.generator import ReportGenerator
24+
25+
__all__ = [
26+
"DatasetItem",
27+
"DatasetFormat",
28+
"ChatMessage",
29+
"QualityScore",
30+
"RefinementResult",
31+
"EvolutionResult",
32+
"PreferenceResult",
33+
"PipelineConfig",
34+
"GeminiClient",
35+
"QualityScorer",
36+
"FastRuleFilter",
37+
"DataRefiner",
38+
"DataEvolver",
39+
"PreferenceBuilder",
40+
"Deduplicator",
41+
"ReportGenerator",
42+
]

buffdata/cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from buffdata.cli.main import app
2+
3+
__all__ = ["app"]

0 commit comments

Comments
 (0)