|
| 1 | +# rStar-Math Demonstrator |
| 2 | + |
| 3 | +An AI Agent that demonstrates the principles and performance of the rStar-Math framework, with capabilities to generate integration code for other chatbots and AI agents. |
| 4 | + |
| 5 | +The development of this GitHub Repository was inspired by the "rStar-Math: Small LLMs Can Master Math Reasoning with Self-Evolved Deep Thinking" paper. To read the full paper, visit https://arxiv.org/pdf/2501.04519 |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **Core Components** |
| 10 | + - Monte Carlo Tree Search (MCTS) for step-by-step reasoning |
| 11 | + - Process Preference Model (PPM) for evaluating solution quality |
| 12 | + - Flexible model interface supporting multiple LLMs |
| 13 | + |
| 14 | +- **Model Support** |
| 15 | + - OpenAI (GPT-4, GPT-3.5) |
| 16 | + - Anthropic (Claude) |
| 17 | + - Mistral AI |
| 18 | + - Groq |
| 19 | + - Google Gemini |
| 20 | + - Local models via llama.cpp |
| 21 | + |
| 22 | +- **Integration Templates** |
| 23 | + - Rasa chatbot framework |
| 24 | + - LangChain |
| 25 | + - Azure Bot Framework |
| 26 | + - Streamlit |
| 27 | + - Gradio |
| 28 | + |
| 29 | +- **Example Notebooks** |
| 30 | + - Calculus with visualizations |
| 31 | + - Geometry and proofs |
| 32 | + - Linear algebra operations |
| 33 | + - Statistics and probability |
| 34 | + - Model comparison studies |
| 35 | + |
| 36 | +- **Development Tools** |
| 37 | + - Comprehensive test suite |
| 38 | + - Performance benchmarking |
| 39 | + - Visualization components |
| 40 | + - API documentation |
| 41 | + |
| 42 | +## Installation |
| 43 | + |
| 44 | +### Option 1: Install from PyPI |
| 45 | + |
| 46 | +```bash |
| 47 | +pip install rstar-math |
| 48 | +``` |
| 49 | + |
| 50 | +### Option 2: Install from Source |
| 51 | + |
| 52 | +1. Clone the repository: |
| 53 | +```bash |
| 54 | +git clone https://github.com/yourusername/rStar-Math.git |
| 55 | +cd rStar-Math |
| 56 | +``` |
| 57 | + |
| 58 | +2. Create a virtual environment: |
| 59 | +```bash |
| 60 | +python -m venv venv |
| 61 | + |
| 62 | +# Windows |
| 63 | +venv\Scripts\activate |
| 64 | + |
| 65 | +# Unix/MacOS |
| 66 | +source venv/bin/activate |
| 67 | +``` |
| 68 | + |
| 69 | +3. Install dependencies: |
| 70 | +```bash |
| 71 | +pip install -r requirements.txt |
| 72 | +``` |
| 73 | + |
| 74 | +4. Install in development mode: |
| 75 | +```bash |
| 76 | +pip install -e . |
| 77 | +``` |
| 78 | + |
| 79 | +### Setting up API Keys |
| 80 | + |
| 81 | +Create a `.env` file in the project root: |
| 82 | +```bash |
| 83 | +OPENAI_API_KEY=your_openai_key |
| 84 | +ANTHROPIC_API_KEY=your_anthropic_key |
| 85 | +MISTRAL_API_KEY=your_mistral_key |
| 86 | +GROQ_API_KEY=your_groq_key |
| 87 | +GEMINI_API_KEY=your_gemini_key |
| 88 | +``` |
| 89 | + |
| 90 | +## Running the Project |
| 91 | + |
| 92 | +### 1. Run Interactive Demos |
| 93 | + |
| 94 | +#### Gradio Interface |
| 95 | +```bash |
| 96 | +python examples/gradio_integration.py |
| 97 | +``` |
| 98 | + |
| 99 | +#### Streamlit Dashboard |
| 100 | +```bash |
| 101 | +streamlit run examples/streamlit_integration.py |
| 102 | +``` |
| 103 | + |
| 104 | +### 2. Run Example Notebooks |
| 105 | + |
| 106 | +```bash |
| 107 | +# Start Jupyter server |
| 108 | +jupyter lab |
| 109 | + |
| 110 | +# Navigate to examples/notebooks/ |
| 111 | +# Open any of: |
| 112 | +# - calculus_examples.ipynb |
| 113 | +# - geometry_examples.ipynb |
| 114 | +# - linear_algebra_examples.ipynb |
| 115 | +# - statistics_examples.ipynb |
| 116 | +``` |
| 117 | + |
| 118 | +### 3. Run Tests |
| 119 | + |
| 120 | +```bash |
| 121 | +# Run all tests |
| 122 | +pytest tests/ |
| 123 | + |
| 124 | +# Run specific test suite |
| 125 | +pytest tests/test_new_models.py |
| 126 | + |
| 127 | +# Run with coverage report |
| 128 | +pytest --cov=src tests/ |
| 129 | +``` |
| 130 | + |
| 131 | +### 4. Run Benchmarks |
| 132 | + |
| 133 | +```bash |
| 134 | +# Run full benchmark suite |
| 135 | +python tools/benchmark.py |
| 136 | + |
| 137 | +# View results in browser |
| 138 | +python -m http.server 8000 |
| 139 | +# Open http://localhost:8000/benchmark_results/ |
| 140 | +``` |
| 141 | + |
| 142 | +### 5. Framework Integrations |
| 143 | + |
| 144 | +#### Rasa Integration |
| 145 | +```bash |
| 146 | +# In your Rasa project |
| 147 | +pip install rstar-math |
| 148 | +cp examples/rasa_integration.py actions/ |
| 149 | +``` |
| 150 | + |
| 151 | +#### LangChain Integration |
| 152 | +```python |
| 153 | +from examples.langchain_integration import RStarMathChain |
| 154 | +chain = RStarMathChain() |
| 155 | +``` |
| 156 | + |
| 157 | +#### Azure Bot Integration |
| 158 | +```bash |
| 159 | +# In your Azure Bot project |
| 160 | +pip install rstar-math |
| 161 | +cp examples/azure_bot_integration.py bot/ |
| 162 | +``` |
| 163 | + |
| 164 | +### 6. Local Model Setup |
| 165 | + |
| 166 | +1. Download a compatible model: |
| 167 | +```bash |
| 168 | +# Example: Download LLaMA model |
| 169 | +wget https://huggingface.co/models/llama-7b/resolve/main/model.bin -O models/llama-7b.bin |
| 170 | +``` |
| 171 | + |
| 172 | +2. Run with local model: |
| 173 | +```python |
| 174 | +from examples.llama_cpp_integration import LlamaCppModel |
| 175 | +model = LlamaCppModel("models/llama-7b.bin") |
| 176 | +``` |
| 177 | + |
| 178 | +## Quick Start |
| 179 | + |
| 180 | +```python |
| 181 | +from rstar_math.core import MCTS, PPM |
| 182 | +from rstar_math.models import ModelFactory |
| 183 | + |
| 184 | +# Initialize components |
| 185 | +mcts = MCTS.from_config_file('config/default.json') |
| 186 | +ppm = ProcessPreferenceModel.from_config_file('config/default.json') |
| 187 | +model = ModelFactory.create_model('openai', 'YOUR_API_KEY', 'config/default.json') |
| 188 | + |
| 189 | +# Solve a problem |
| 190 | +problem = "What is the derivative of f(x) = x^2 + 3x?" |
| 191 | +action, trajectory = mcts.search(problem) |
| 192 | + |
| 193 | +# Print solution steps with confidence scores |
| 194 | +for step in trajectory: |
| 195 | + confidence = ppm.evaluate_step(step['state'], model) |
| 196 | + print(f"Step: {step['state']}") |
| 197 | + print(f"Confidence: {confidence:.2f}\n") |
| 198 | +``` |
| 199 | + |
| 200 | +## Example Applications |
| 201 | + |
| 202 | +### 1. Interactive Web Interface |
| 203 | + |
| 204 | +```python |
| 205 | +from examples.gradio_integration import RStarMathGradio |
| 206 | + |
| 207 | +# Launch Gradio interface |
| 208 | +demo = RStarMathGradio() |
| 209 | +demo.launch() |
| 210 | +``` |
| 211 | + |
| 212 | +### 2. Chatbot Integration |
| 213 | + |
| 214 | +```python |
| 215 | +from examples.rasa_integration import RStarMathAction |
| 216 | + |
| 217 | +# Use in Rasa custom action |
| 218 | +action = RStarMathAction() |
| 219 | +await action.run(dispatcher, tracker, domain) |
| 220 | +``` |
| 221 | + |
| 222 | +### 3. Local Model Inference |
| 223 | + |
| 224 | +```python |
| 225 | +from examples.llama_cpp_integration import LlamaCppModel |
| 226 | + |
| 227 | +# Initialize local model |
| 228 | +model = LlamaCppModel("path/to/model.bin") |
| 229 | +response = model.generate_response("What is 2 + 2?") |
| 230 | +``` |
| 231 | + |
| 232 | +## Documentation |
| 233 | + |
| 234 | +- [API Reference](docs/api.md) |
| 235 | +- [Model Integration Guide](docs/model_integration.md) |
| 236 | +- [Example Notebooks](examples/notebooks/) |
| 237 | +- [Benchmark Results](docs/benchmarks.md) |
| 238 | + |
| 239 | +## Benchmarking |
| 240 | + |
| 241 | +Run performance benchmarks: |
| 242 | + |
| 243 | +```bash |
| 244 | +python tools/benchmark.py |
| 245 | +``` |
| 246 | + |
| 247 | +This will generate: |
| 248 | +- Execution time comparisons |
| 249 | +- Memory usage analysis |
| 250 | +- Token count statistics |
| 251 | +- Confidence score trends |
| 252 | + |
| 253 | +## Contributing |
| 254 | + |
| 255 | +1. Fork the repository |
| 256 | +2. Create your feature branch |
| 257 | +3. Run tests: `pytest tests/` |
| 258 | +4. Submit a pull request |
| 259 | + |
| 260 | +## License |
| 261 | + |
| 262 | +MIT License - see LICENSE file for details |
| 263 | + |
| 264 | +## Citation |
| 265 | + |
| 266 | +If you use rStar-Math in your research, please cite: |
| 267 | + |
| 268 | +```bibtex |
| 269 | +@article{rstar2024, |
| 270 | + title={rStar-Math: Small LLMs Can Master Math Reasoning with Self-Evolved Deep Thinking}, |
| 271 | + author={Original Authors}, |
| 272 | + journal={arXiv preprint}, |
| 273 | + year={2024} |
| 274 | +} |
| 275 | +``` |
| 276 | + |
| 277 | +## Acknowledgments |
| 278 | + |
| 279 | +This project is inspired by the paper "rStar-Math: Small LLMs Can Master Math Reasoning with Self-Evolved Deep Thinking" (https://arxiv.org/pdf/2501.04519). |
| 280 | + |
| 281 | +## Project Structure |
| 282 | + |
| 283 | +``` |
| 284 | +rStar-Math/ |
| 285 | +├── src/ # Source code |
| 286 | +│ ├── core/ # Core components (MCTS, PPM) |
| 287 | +│ ├── models/ # Model implementations |
| 288 | +│ └── utils/ # Utility functions |
| 289 | +├── tests/ # Test suites |
| 290 | +├── examples/ # Example integrations |
| 291 | +│ ├── notebooks/ # Jupyter notebooks |
| 292 | +│ └── frameworks/ # Framework integrations |
| 293 | +├── docs/ # Documentation |
| 294 | +├── tools/ # Development tools |
| 295 | +└── config/ # Configuration files |
| 296 | +``` |
| 297 | + |
| 298 | +## Development Workflow |
| 299 | + |
| 300 | +1. Create a new feature branch: |
| 301 | +```bash |
| 302 | +git checkout -b feature/your-feature-name |
| 303 | +``` |
| 304 | + |
| 305 | +2. Make changes and run tests: |
| 306 | +```bash |
| 307 | +# Format code |
| 308 | +black src/ tests/ |
| 309 | + |
| 310 | +# Run linter |
| 311 | +flake8 src/ tests/ |
| 312 | + |
| 313 | +# Run tests |
| 314 | +pytest tests/ |
| 315 | +``` |
| 316 | + |
| 317 | +3. Submit a pull request: |
| 318 | +```bash |
| 319 | +git add . |
| 320 | +git commit -m "feat: your feature description" |
| 321 | +git push origin feature/your-feature-name |
| 322 | +``` |
| 323 | + |
| 324 | +## Troubleshooting |
| 325 | + |
| 326 | +### Common Issues |
| 327 | + |
| 328 | +1. API Key Issues: |
| 329 | +```bash |
| 330 | +# Check if keys are loaded |
| 331 | +python -c "import os; print(os.getenv('OPENAI_API_KEY'))" |
| 332 | +``` |
| 333 | + |
| 334 | +2. Model Loading Issues: |
| 335 | +```bash |
| 336 | +# Verify model files |
| 337 | +ls models/ |
| 338 | +``` |
| 339 | + |
| 340 | +3. CUDA Issues: |
| 341 | +```bash |
| 342 | +# Check CUDA availability |
| 343 | +python -c "import torch; print(torch.cuda.is_available())" |
| 344 | +``` |
| 345 | + |
| 346 | +For more issues, check the [troubleshooting guide](docs/troubleshooting.md). |
0 commit comments