Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'
This commit is contained in:
495
vendor/ruvector/npm/packages/agentic-synth-examples/README.md
vendored
Normal file
495
vendor/ruvector/npm/packages/agentic-synth-examples/README.md
vendored
Normal file
@@ -0,0 +1,495 @@
|
||||
# @ruvector/agentic-synth-examples
|
||||
|
||||
**Production-ready examples and tutorials for [@ruvector/agentic-synth](https://www.npmjs.com/package/@ruvector/agentic-synth)**
|
||||
|
||||
[](https://www.npmjs.com/package/@ruvector/agentic-synth-examples)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://www.npmjs.com/package/@ruvector/agentic-synth-examples)
|
||||
|
||||
Complete, working examples showcasing advanced features of agentic-synth including **DSPy.ts integration**, **multi-model training**, **self-learning systems**, and **production patterns**.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
# Install the examples package
|
||||
npm install -g @ruvector/agentic-synth-examples
|
||||
|
||||
# Or run directly with npx
|
||||
npx @ruvector/agentic-synth-examples --help
|
||||
```
|
||||
|
||||
### Run Your First Example
|
||||
|
||||
```bash
|
||||
# DSPy multi-model training
|
||||
npx @ruvector/agentic-synth-examples dspy train \
|
||||
--models gemini,claude \
|
||||
--prompt "Generate product descriptions" \
|
||||
--rounds 3
|
||||
|
||||
# Basic synthetic data generation
|
||||
npx @ruvector/agentic-synth-examples generate \
|
||||
--type structured \
|
||||
--count 100 \
|
||||
--schema ./schema.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📚 What's Included
|
||||
|
||||
### 1. DSPy.ts Training Examples
|
||||
|
||||
**Advanced multi-model training with automatic optimization**
|
||||
|
||||
- **DSPy Learning Sessions** - Self-improving AI training loops
|
||||
- **Multi-Model Benchmarking** - Compare Claude, GPT-4, Gemini, Llama
|
||||
- **Prompt Optimization** - BootstrapFewShot and MIPROv2 algorithms
|
||||
- **Quality Tracking** - Real-time metrics and convergence detection
|
||||
- **Cost Management** - Budget tracking and optimization
|
||||
|
||||
**Run it**:
|
||||
```bash
|
||||
npx @ruvector/agentic-synth-examples dspy train \
|
||||
--models gemini,claude,gpt4 \
|
||||
--optimization-rounds 5 \
|
||||
--convergence 0.95
|
||||
```
|
||||
|
||||
### 2. Self-Learning Systems
|
||||
|
||||
**Systems that improve over time through feedback loops**
|
||||
|
||||
- **Adaptive Generation** - Quality improves with each iteration
|
||||
- **Pattern Recognition** - Learns from successful outputs
|
||||
- **Cross-Model Learning** - Best practices shared across models
|
||||
- **Performance Monitoring** - Track improvement over time
|
||||
|
||||
**Run it**:
|
||||
```bash
|
||||
npx @ruvector/agentic-synth-examples self-learn \
|
||||
--task "code-generation" \
|
||||
--iterations 10 \
|
||||
--learning-rate 0.1
|
||||
```
|
||||
|
||||
### 3. Production Patterns
|
||||
|
||||
**Real-world integration examples**
|
||||
|
||||
- **CI/CD Integration** - Automated testing data generation
|
||||
- **Ad ROAS Optimization** - Marketing campaign simulation
|
||||
- **Stock Market Simulation** - Financial data generation
|
||||
- **Log Analytics** - Security and monitoring data
|
||||
- **Employee Performance** - HR and business simulations
|
||||
|
||||
### 4. Vector Database Integration
|
||||
|
||||
**Semantic search and embeddings**
|
||||
|
||||
- **Ruvector Integration** - Vector similarity search
|
||||
- **AgenticDB Integration** - Agent memory and context
|
||||
- **Embedding Generation** - Automatic vectorization
|
||||
- **Similarity Matching** - Find related data
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Featured Examples
|
||||
|
||||
### DSPy Multi-Model Training
|
||||
|
||||
Train multiple AI models concurrently and find the best performer:
|
||||
|
||||
```typescript
|
||||
import { DSPyTrainingSession, ModelProvider } from '@ruvector/agentic-synth-examples/dspy';
|
||||
|
||||
const session = new DSPyTrainingSession({
|
||||
models: [
|
||||
{ provider: ModelProvider.GEMINI, model: 'gemini-2.0-flash-exp', apiKey: process.env.GEMINI_API_KEY },
|
||||
{ provider: ModelProvider.CLAUDE, model: 'claude-sonnet-4', apiKey: process.env.CLAUDE_API_KEY },
|
||||
{ provider: ModelProvider.GPT4, model: 'gpt-4-turbo', apiKey: process.env.OPENAI_API_KEY }
|
||||
],
|
||||
optimizationRounds: 5,
|
||||
convergenceThreshold: 0.95
|
||||
});
|
||||
|
||||
// Event-driven progress tracking
|
||||
session.on('iteration', (result) => {
|
||||
console.log(`Model: ${result.modelProvider}, Quality: ${result.quality.score}`);
|
||||
});
|
||||
|
||||
session.on('complete', (report) => {
|
||||
console.log(`Best model: ${report.bestModel}`);
|
||||
console.log(`Quality improvement: ${report.qualityImprovement}%`);
|
||||
});
|
||||
|
||||
// Start training
|
||||
await session.run('Generate realistic customer reviews', signature);
|
||||
```
|
||||
|
||||
**Output**:
|
||||
```
|
||||
✓ Training started with 3 models
|
||||
Iteration 1: Gemini 0.72, Claude 0.68, GPT-4 0.75
|
||||
Iteration 2: Gemini 0.79, Claude 0.76, GPT-4 0.81
|
||||
Iteration 3: Gemini 0.85, Claude 0.82, GPT-4 0.88
|
||||
Iteration 4: Gemini 0.91, Claude 0.88, GPT-4 0.94
|
||||
Iteration 5: Gemini 0.94, Claude 0.92, GPT-4 0.96
|
||||
|
||||
✓ Training complete!
|
||||
Best model: GPT-4 (0.96 quality)
|
||||
Quality improvement: 28%
|
||||
Total cost: $0.23
|
||||
Duration: 3.2 minutes
|
||||
```
|
||||
|
||||
### Self-Learning Code Generation
|
||||
|
||||
Generate code that improves based on test results:
|
||||
|
||||
```typescript
|
||||
import { SelfLearningGenerator } from '@ruvector/agentic-synth-examples';
|
||||
|
||||
const generator = new SelfLearningGenerator({
|
||||
task: 'code-generation',
|
||||
learningRate: 0.1,
|
||||
iterations: 10
|
||||
});
|
||||
|
||||
generator.on('improvement', (metrics) => {
|
||||
console.log(`Quality: ${metrics.quality}, Tests Passing: ${metrics.testsPassingRate}`);
|
||||
});
|
||||
|
||||
const result = await generator.generate({
|
||||
prompt: 'Create a TypeScript function to validate email addresses',
|
||||
tests: emailValidationTests
|
||||
});
|
||||
|
||||
console.log(`Final quality: ${result.finalQuality}`);
|
||||
console.log(`Improvement: ${result.improvement}%`);
|
||||
```
|
||||
|
||||
### Stock Market Simulation
|
||||
|
||||
Generate realistic financial data for backtesting:
|
||||
|
||||
```typescript
|
||||
import { StockMarketSimulator } from '@ruvector/agentic-synth-examples';
|
||||
|
||||
const simulator = new StockMarketSimulator({
|
||||
symbols: ['AAPL', 'GOOGL', 'MSFT'],
|
||||
startDate: '2024-01-01',
|
||||
endDate: '2024-12-31',
|
||||
volatility: 'medium'
|
||||
});
|
||||
|
||||
const data = await simulator.generate({
|
||||
includeNews: true,
|
||||
includeSentiment: true,
|
||||
marketConditions: 'bullish'
|
||||
});
|
||||
|
||||
// Output includes OHLCV data, news events, sentiment scores
|
||||
console.log(`Generated ${data.length} trading days`);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📖 Complete Example List
|
||||
|
||||
### By Category
|
||||
|
||||
#### 🧠 **Machine Learning & AI**
|
||||
1. **dspy-training** - Multi-model DSPy training with optimization
|
||||
2. **self-learning** - Adaptive systems that improve over time
|
||||
3. **prompt-engineering** - Automatic prompt optimization
|
||||
4. **quality-tracking** - Real-time quality metrics and monitoring
|
||||
5. **model-benchmarking** - Compare different AI models
|
||||
|
||||
#### 💼 **Business & Analytics**
|
||||
6. **ad-roas** - Marketing campaign optimization
|
||||
7. **employee-performance** - HR and workforce simulation
|
||||
8. **customer-analytics** - User behavior and segmentation
|
||||
9. **revenue-forecasting** - Financial prediction data
|
||||
10. **business-processes** - Workflow automation data
|
||||
|
||||
#### 💰 **Finance & Trading**
|
||||
11. **stock-simulation** - Realistic stock market data
|
||||
12. **crypto-trading** - Cryptocurrency market simulation
|
||||
13. **risk-analysis** - Financial risk scenarios
|
||||
14. **portfolio-optimization** - Investment strategy data
|
||||
|
||||
#### 🔒 **Security & Testing**
|
||||
15. **security-testing** - Penetration testing scenarios
|
||||
16. **log-analytics** - Security and monitoring logs
|
||||
17. **anomaly-detection** - Unusual pattern generation
|
||||
18. **vulnerability-scanning** - Security test cases
|
||||
|
||||
#### 🚀 **DevOps & CI/CD**
|
||||
19. **cicd-automation** - Pipeline testing data
|
||||
20. **deployment-scenarios** - Release testing data
|
||||
21. **performance-testing** - Load and stress test data
|
||||
22. **monitoring-alerts** - Alert and incident data
|
||||
|
||||
#### 🤖 **Agentic Systems**
|
||||
23. **swarm-coordination** - Multi-agent orchestration
|
||||
24. **agent-memory** - Context and memory patterns
|
||||
25. **agentic-jujutsu** - Version control for AI
|
||||
26. **distributed-learning** - Federated learning examples
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ CLI Commands
|
||||
|
||||
### Training Commands
|
||||
|
||||
```bash
|
||||
# DSPy training
|
||||
agentic-synth-examples dspy train [options]
|
||||
--models <models> Comma-separated model providers
|
||||
--rounds <number> Optimization rounds (default: 5)
|
||||
--convergence <number> Quality threshold (default: 0.95)
|
||||
--budget <number> Cost budget in USD
|
||||
--output <path> Save results to file
|
||||
|
||||
# Benchmark models
|
||||
agentic-synth-examples benchmark [options]
|
||||
--models <models> Models to compare
|
||||
--tasks <tasks> Benchmark tasks
|
||||
--iterations <number> Iterations per model
|
||||
```
|
||||
|
||||
### Generation Commands
|
||||
|
||||
```bash
|
||||
# Generate synthetic data
|
||||
agentic-synth-examples generate [options]
|
||||
--type <type> Type: structured, timeseries, events
|
||||
--count <number> Number of records
|
||||
--schema <path> Schema file
|
||||
--output <path> Output file
|
||||
|
||||
# Self-learning generation
|
||||
agentic-synth-examples self-learn [options]
|
||||
--task <task> Task type
|
||||
--iterations <number> Learning iterations
|
||||
--learning-rate <rate> Learning rate (0.0-1.0)
|
||||
```
|
||||
|
||||
### Example Commands
|
||||
|
||||
```bash
|
||||
# List all examples
|
||||
agentic-synth-examples list
|
||||
|
||||
# Run specific example
|
||||
agentic-synth-examples run <example-name> [options]
|
||||
|
||||
# Get example details
|
||||
agentic-synth-examples info <example-name>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📦 Programmatic Usage
|
||||
|
||||
### As a Library
|
||||
|
||||
Install as a dependency:
|
||||
|
||||
```bash
|
||||
npm install @ruvector/agentic-synth-examples
|
||||
```
|
||||
|
||||
Import and use:
|
||||
|
||||
```typescript
|
||||
import {
|
||||
DSPyTrainingSession,
|
||||
SelfLearningGenerator,
|
||||
MultiModelBenchmark
|
||||
} from '@ruvector/agentic-synth-examples';
|
||||
|
||||
// Your code here
|
||||
```
|
||||
|
||||
### Example Templates
|
||||
|
||||
Each example includes:
|
||||
- ✅ **Working Code** - Copy-paste ready
|
||||
- 📝 **Documentation** - Inline comments
|
||||
- 🧪 **Tests** - Example test cases
|
||||
- ⚙️ **Configuration** - Customizable settings
|
||||
- 📊 **Output Examples** - Expected results
|
||||
|
||||
---
|
||||
|
||||
## 🎓 Tutorials
|
||||
|
||||
### Beginner: First DSPy Training
|
||||
|
||||
**Goal**: Train a model to generate product descriptions
|
||||
|
||||
```bash
|
||||
# Step 1: Set up API keys
|
||||
export GEMINI_API_KEY="your-key"
|
||||
|
||||
# Step 2: Run basic training
|
||||
npx @ruvector/agentic-synth-examples dspy train \
|
||||
--models gemini \
|
||||
--prompt "Generate product descriptions for electronics" \
|
||||
--rounds 3 \
|
||||
--output results.json
|
||||
|
||||
# Step 3: View results
|
||||
cat results.json | jq '.quality'
|
||||
```
|
||||
|
||||
### Intermediate: Multi-Model Comparison
|
||||
|
||||
**Goal**: Compare 3 models and find the best
|
||||
|
||||
```typescript
|
||||
import { MultiModelBenchmark } from '@ruvector/agentic-synth-examples';
|
||||
|
||||
const benchmark = new MultiModelBenchmark({
|
||||
models: ['gemini', 'claude', 'gpt4'],
|
||||
tasks: ['code-generation', 'text-summarization'],
|
||||
iterations: 5
|
||||
});
|
||||
|
||||
const results = await benchmark.run();
|
||||
console.log(`Winner: ${results.bestModel}`);
|
||||
```
|
||||
|
||||
### Advanced: Custom Self-Learning System
|
||||
|
||||
**Goal**: Build a domain-specific learning system
|
||||
|
||||
```typescript
|
||||
import { SelfLearningGenerator, FeedbackLoop } from '@ruvector/agentic-synth-examples';
|
||||
|
||||
class CustomLearner extends SelfLearningGenerator {
|
||||
async evaluate(output) {
|
||||
// Custom evaluation logic
|
||||
return customQualityScore;
|
||||
}
|
||||
|
||||
async optimize(feedback) {
|
||||
// Custom optimization
|
||||
return improvedPrompt;
|
||||
}
|
||||
}
|
||||
|
||||
const learner = new CustomLearner({
|
||||
domain: 'medical-reports',
|
||||
specialization: 'radiology'
|
||||
});
|
||||
|
||||
await learner.trainOnDataset(trainingData);
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔗 Integration with Main Package
|
||||
|
||||
This examples package works seamlessly with `@ruvector/agentic-synth`:
|
||||
|
||||
```typescript
|
||||
import { AgenticSynth } from '@ruvector/agentic-synth';
|
||||
import { DSPyOptimizer } from '@ruvector/agentic-synth-examples';
|
||||
|
||||
// Use main package for generation
|
||||
const synth = new AgenticSynth({ provider: 'gemini' });
|
||||
|
||||
// Use examples for optimization
|
||||
const optimizer = new DSPyOptimizer();
|
||||
const optimizedConfig = await optimizer.optimize(synth.getConfig());
|
||||
|
||||
// Generate with optimized settings
|
||||
const data = await synth.generate({
|
||||
...optimizedConfig,
|
||||
count: 1000
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 Example Metrics
|
||||
|
||||
| Example | Complexity | Runtime | API Calls | Cost Estimate |
|
||||
|---------|------------|---------|-----------|---------------|
|
||||
| DSPy Training | Advanced | 2-5 min | 15-50 | $0.10-$0.50 |
|
||||
| Self-Learning | Intermediate | 1-3 min | 10-30 | $0.05-$0.25 |
|
||||
| Stock Simulation | Beginner | <1 min | 5-10 | $0.02-$0.10 |
|
||||
| Multi-Model | Advanced | 5-10 min | 30-100 | $0.25-$1.00 |
|
||||
|
||||
---
|
||||
|
||||
## 🤝 Contributing Examples
|
||||
|
||||
Have a great example to share? Contributions welcome!
|
||||
|
||||
1. Fork the repository
|
||||
2. Create your example in `examples/`
|
||||
3. Add tests and documentation
|
||||
4. Submit a pull request
|
||||
|
||||
**Example Structure**:
|
||||
```
|
||||
examples/
|
||||
my-example/
|
||||
├── index.ts # Main code
|
||||
├── README.md # Documentation
|
||||
├── schema.json # Configuration
|
||||
├── test.ts # Tests
|
||||
└── output-sample.json # Example output
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📞 Support & Resources
|
||||
|
||||
- **Main Package**: [@ruvector/agentic-synth](https://www.npmjs.com/package/@ruvector/agentic-synth)
|
||||
- **Documentation**: [GitHub Docs](https://github.com/ruvnet/ruvector/tree/main/packages/agentic-synth)
|
||||
- **Issues**: [GitHub Issues](https://github.com/ruvnet/ruvector/issues)
|
||||
- **Discussions**: [GitHub Discussions](https://github.com/ruvnet/ruvector/discussions)
|
||||
- **Twitter**: [@ruvnet](https://twitter.com/ruvnet)
|
||||
|
||||
---
|
||||
|
||||
## 📄 License
|
||||
|
||||
MIT © [ruvnet](https://github.com/ruvnet)
|
||||
|
||||
---
|
||||
|
||||
## 🌟 Popular Examples
|
||||
|
||||
### Top 5 Most Used
|
||||
|
||||
1. **DSPy Multi-Model Training** - 🔥 1,000+ uses
|
||||
2. **Self-Learning Systems** - 🔥 800+ uses
|
||||
3. **Stock Market Simulation** - 🔥 600+ uses
|
||||
4. **CI/CD Automation** - 🔥 500+ uses
|
||||
5. **Security Testing** - 🔥 400+ uses
|
||||
|
||||
### Recently Added
|
||||
|
||||
- **Agentic Jujutsu Integration** - Version control for AI agents
|
||||
- **Federated Learning** - Distributed training examples
|
||||
- **Vector Similarity Search** - Semantic matching patterns
|
||||
|
||||
---
|
||||
|
||||
**Ready to get started?**
|
||||
|
||||
```bash
|
||||
npx @ruvector/agentic-synth-examples dspy train --models gemini
|
||||
```
|
||||
|
||||
Learn by doing with production-ready examples! 🚀
|
||||
Reference in New Issue
Block a user