File size: 8,791 Bytes
9004ebd
 
 
 
 
 
 
2287eaf
9004ebd
 
5b7e231
9004ebd
 
10cbeea
3e1d0f5
 
 
10cbeea
3e1d0f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10cbeea
3e1d0f5
10cbeea
3e1d0f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10cbeea
3e1d0f5
 
 
 
 
10cbeea
 
 
 
 
 
 
3e1d0f5
 
10cbeea
3e1d0f5
 
 
10cbeea
3e1d0f5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
---
title: ReasonaIQ
emoji: 🐨
colorFrom: purple
colorTo: pink
sdk: gradio
sdk_version: 5.49.0
app_file: main.py
pinned: false
license: mit
short_description: 'Advanced AI Reasoning with Multiple Strategies'
---

# πŸ”¬ ReasonaIQ - Advanced AI Reasoning Research System

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Gradio](https://img.shields.io/badge/gradio-5.49.0-orange.svg)](https://gradio.app/)

An open-source research platform that implements cutting-edge AI reasoning methodologies including **Tree of Thoughts**, **Constitutional AI**, and **multi-agent debate patterns**. Features a modern web interface, real-time streaming, and comprehensive analytics.

---

## 🎯 What This Project Does

- **Multi-Strategy Reasoning**: Apply different reasoning approaches to the same problem
- **Self-Critique System**: AI reviews and improves its own responses
- **Real-time Analytics**: Track reasoning depth, confidence, and performance metrics
- **Export & Documentation**: Save conversations as PDF, Markdown, or JSON
- **Production Ready**: Caching, rate limiting, error handling, and automatic backups

---

## πŸš€ Quick Start (2 Minutes)

### Prerequisites

- Python **3.8+**
- Groq API key (free at [console.groq.com](https://console.groq.com))

### Installation

```bash
# Clone repository
git clone https://github.com/your-username/ai-reasoning-system.git
cd ai-reasoning-system

# Create virtual environment
python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure API key
echo "GROQ_API_KEY=your_key_here" > .env

# Launch system
python main.py
```

Open your browser to `http://localhost:7860` and start exploring!

---

## πŸ“Š Reasoning Strategies

| Method | Description | Best For |
|--------|-------------|----------|
| **Tree of Thoughts** | Explores multiple reasoning paths systematically | Complex problems with multiple solutions |
| **Chain of Thought** | Step-by-step transparent reasoning | Mathematical problems, logic puzzles |
| **Self-Consistency** | Generates multiple answers and finds consensus | Factual questions, reliability important |
| **Reflexion** | Self-critique and iterative improvement | Creative writing, analysis tasks |
| **Multi-Agent Debate** | Presents multiple perspectives | Ethical dilemmas, policy questions |
| **Analogical Reasoning** | Finds similar problems and adapts solutions | Novel problems, innovation tasks |

---

## πŸŽ₯ Demo Features

### Real-time Interface

- **Streaming Responses**: Watch reasoning unfold in real-time
- **Live Metrics**: See inference time, tokens/second, reasoning depth
- **Interactive Controls**: Switch models, adjust temperature, enable critique
- **Modern Design**: Clean, responsive interface with dark theme

### Analytics Dashboard

- Session performance metrics
- Model usage distribution
- Cache hit rates
- Error tracking and retry statistics

### Export Options

- **PDF**: Professional reports with formatting
- **Markdown**: GitHub-friendly documentation
- **JSON**: Machine-readable data
- **Plain Text**: Simple conversation logs

---

## πŸ”§ Configuration

Key settings in `config.py`:

```python
MAX_HISTORY_LENGTH = 10          # Messages in context
CACHE_SIZE = 100                 # Cached responses
RATE_LIMIT_REQUESTS = 50         # Per minute
DEFAULT_TEMPERATURE = 0.7        # Creativity level
MAX_TOKENS = 4000                # Response length
```

---

## πŸ—οΈ Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Gradio UI     β”‚    β”‚  Core Engine    β”‚    β”‚   Groq API      β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Chat Interface│◄──►│ β€’ Reasoning     │◄──►│ β€’ LLM Models    β”‚
β”‚ β€’ Controls      β”‚    β”‚ β€’ Caching       β”‚    β”‚ β€’ Streaming     β”‚
β”‚ β€’ Metrics       β”‚    β”‚ β€’ Rate Limiting β”‚    β”‚ β€’ Token Count   β”‚
β”‚ β€’ Export        β”‚    β”‚ β€’ Error Handlingβ”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ“ˆ Performance

- **Cold Start**: ~2 seconds
- **Time to First Token**: 0.3–1.2 seconds
- **Throughput**: Up to 100 tokens/second
- **Memory Usage**: ~100MB base + conversation history
- **Concurrent Users**: Limited by Groq rate limits (50 req/min)

---

## πŸ§ͺ Example Use Cases

### Research Analysis

```
User: "Analyze the impact of remote work on productivity"
System: Uses Tree of Thoughts to explore economic, psychological, and technological factors
```

### Code Review

```
User: "Review this Python function for errors"
System: Applies Chain of Thought to identify bugs, suggest improvements
```

### Creative Writing

```
User: "Write a story about AI consciousness"
System: Uses Reflexion to draft, critique, and refine the narrative
```

### Decision Making

```
User: "Should we implement a four-day work week?"
System: Multi-Agent Debate presents management and employee perspectives
```

---

## πŸ“š Research Foundation

Built on seminal papers:

- **Tree of Thoughts** (Yao et al., 2023) – Systematic exploration
- **Constitutional AI** (Bai et al., 2022) – Self-critique mechanisms
- **Chain of Thought** (Wei et al., 2022) – Transparent reasoning
- **Reflexion** (Shinn et al., 2023) – Iterative improvement
- **Self-Consistency** (Wang et al., 2022) – Consensus building

---

## πŸ” Project Structure

```
ai-reasoning-system/
β”œβ”€β”€ main.py              # Gradio interface and event handlers
β”œβ”€β”€ core.py              # Business logic and reasoning engine
β”œβ”€β”€ config.py            # Configuration and constants
β”œβ”€β”€ requirements.txt     # Dependencies
β”œβ”€β”€ README.md            # Project documentation
β”œβ”€β”€ .env                 # API keys (created by user)
β”œβ”€β”€ exports/             # Exported conversations
β”œβ”€β”€ backups/             # Automatic backups
└── reasoning_system.log # Application logs
```

---

## πŸ§ͺ Development

### Running Tests

```bash
# Install test dependencies
pip install pytest pytest-cov

# Run tests
pytest tests/ -v --cov=core
```

### Adding New Reasoning Mode

1. Add enum value in `ReasoningMode`
2. Add system prompt in `PromptEngine.SYSTEM_PROMPTS`
3. Add reasoning template in `PromptEngine.REASONING_PROMPTS`
4. Update UI choices in `main.py`

### Custom Models

Add to `ModelConfig` enum:

```python
CUSTOM_MODEL = ("custom-model-id", parameters, context_length, "Description")
```

---

## πŸ”§ Troubleshooting

| Issue | Solution |
|-------|----------|
| API Key Error | Check `.env` file format: `GROQ_API_KEY=gsk_...` |
| Rate Limit Hit | Wait 60 seconds or reduce request frequency |
| Memory Issues | Reduce `MAX_CONVERSATION_STORAGE` in config |
| PDF Export Fails | Install reportlab: `pip install reportlab` |
| Port Already in Use | Change port: `python main.py --port 7861` |

---

## πŸ“„ License

This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

---

## πŸŽ“ Academic Use

Perfect for:

- Final year projects
- Research demonstrations
- AI methodology studies
- Human-AI interaction experiments

### Citation

```bibtex
@software{ai_reasoning_system_2025,
  title = {ReasonaIQ - Advanced AI Reasoning Research System},
  year = {2025},
  url = {https://huggingface.co/spaces/Dhruv-18/ReasonaIQ}
}
```

---

## 🀝 Contributing

1. Fork the repository
2. Create feature branch: `git checkout -b feature-name`
3. Commit changes: `git commit -m "Add feature"`
4. Push to branch: `git push origin feature-name`
5. Submit Pull Request

---

## πŸ“ž Support

- Create an [issue](https://huggingface.co/spaces/Dhruv-18/ReasonaIQ/discussions) for bugs or features
- Check existing issues before creating new ones
- Include system details and error logs

---

## πŸ”— Links

- **HuggingFace Space**: [ReasonaIQ](https://huggingface.co/spaces/Dhruv-18/ReasonaIQ)
- **Configuration Reference**: [HuggingFace Spaces Config](https://huggingface.co/docs/hub/spaces-config-reference)

---

<div align="center">

### ⭐ Star this space if you find it helpful!

Made with ❀️ by the AI Research Community

[Report Bug](https://huggingface.co/spaces/Dhruv-18/ReasonaIQ/discussions) Β· [Request Feature](https://huggingface.co/spaces/Dhruv-18/ReasonaIQ/discussions)

</div>