File size: 7,623 Bytes
d0fdbcd | 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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | # Getting Started Guide
## Quick Start (5 minutes)
### 1. Install Dependencies
```bash
cd "ai intern project"
pip install -r requirements.txt
```
### 2. Run Demo
```bash
python quickstart.py
```
You should see output like:
```
π€ AI PLATFORM ENGINEER - CODE GENERATION SYSTEM
β Generation Status: success
β Executable: YES β
β Database Tables: 3
β API Endpoints: 15
```
### 3. Try the Web Interface
```bash
python web/app.py
```
Open your browser: **http://localhost:5000**
- Enter a prompt in the input box
- Click "Generate Configuration"
- See the JSON output with validation report
---
## Installation Details
### Requirements
- Python 3.8+
- pip (Python package manager)
### Step-by-Step Setup
#### 1. Create Virtual Environment (Optional but Recommended)
```bash
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/Mac
python3 -m venv venv
source venv/bin/activate
```
#### 2. Install Dependencies
```bash
pip install -r requirements.txt
```
This installs:
- `flask` - Web framework
- `flask-cors` - Cross-origin support
- `anthropic` - LLM API (optional)
- `python-dotenv` - Environment variables
#### 3. (Optional) Set Up Anthropic API
For LLM-powered generation (optional):
```bash
# Windows
set ANTHROPIC_API_KEY=your-key-here
# Linux/Mac
export ANTHROPIC_API_KEY=your-key-here
```
Or create `.env` file:
```
ANTHROPIC_API_KEY=your-key-here
```
---
## Usage Modes
### Mode 1: Quick Start Demo
Generate 3 example configurations:
```bash
python quickstart.py
```
**Output**: Demonstrates pipeline stages and validation
---
### Mode 2: Web Interface
Interactive UI for generation:
```bash
python web/app.py
```
**Features**:
- Enter natural language prompts
- Real-time JSON output
- Validation reports
- Example generation
**Access**: http://localhost:5000
---
### Mode 3: Evaluation Framework
Run comprehensive tests (20 prompts):
```bash
python run_evaluation.py
```
**Output**:
- Success rates (100% in current version)
- Performance metrics
- Cost analysis
- JSON report saved to `evaluation_report_*.json`
---
### Mode 4: Python Library
Use the system programmatically:
```python
from src.pipeline import Pipeline
from src.runtime_simulator import validate_config_executable
# Initialize
pipeline = Pipeline(use_llm=False) # Rule-based
# pipeline = Pipeline(use_llm=True) # LLM-based (requires API key)
# Generate
prompt = "Build a CRM with login, contacts, dashboard"
config, exec_log = pipeline.generate(prompt)
# Validate
is_executable, report = validate_config_executable(config)
print(f"Success: {exec_log['final_status']}")
print(f"Executable: {is_executable}")
```
---
## Project Structure
```
ai intern project/
βββ src/
β βββ schemas.py # Data structures
β βββ pipeline.py # Main 4-stage pipeline
β βββ validator.py # Validation engine
β βββ repair_engine.py # Repair system
β βββ runtime_simulator.py # Executability checks
β
βββ web/
β βββ app.py # Flask API server
β βββ templates/
β β βββ index.html # Web interface
β βββ static/ # Assets (CSS, JS)
β
βββ evaluation/
β βββ test_dataset.py # 20 test prompts
β βββ evaluator.py # Evaluation framework
β
βββ quickstart.py # Demo script
βββ run_evaluation.py # Evaluation runner
βββ requirements.txt # Dependencies
βββ README.md # Main documentation
βββ ARCHITECTURE.md # System design
βββ API.md # API documentation
βββ GETTING_STARTED.md # This file
```
---
## Common Tasks
### Generate a Configuration
**Option 1: Via Web UI**
1. Open http://localhost:5000
2. Enter your prompt
3. Click "Generate"
4. See JSON output
**Option 2: Via API**
```bash
curl -X POST http://localhost:5000/api/generate \
-H "Content-Type: application/json" \
-d '{"prompt":"Build a todo app"}'
```
**Option 3: Via Python**
```python
from src.pipeline import Pipeline
pipeline = Pipeline()
config, log = pipeline.generate("Build a todo app")
```
### Check System Status
```bash
# Web interface
curl http://localhost:5000/api/health
# Quick demo
python quickstart.py
# Full evaluation
python run_evaluation.py
```
### Customize the System
**Edit intent extraction patterns**: `src/pipeline.py` β `IntentExtractor`
**Add new validation rules**: `src/validator.py` β `Validator`
**Modify repair logic**: `src/repair_engine.py` β `RepairEngine`
**Add test prompts**: `evaluation/test_dataset.py` β `TEST_PROMPTS`
---
## Troubleshooting
### Issue: Module not found error
```
ModuleNotFoundError: No module named 'flask'
```
**Solution**:
```bash
pip install -r requirements.txt
```
### Issue: Port 5000 already in use
```
Address already in use
```
**Solution**:
```bash
# Option 1: Kill the process using port 5000
# Windows
netstat -ano | findstr :5000
taskkill /PID <PID> /F
# Option 2: Use different port in app.py
app.run(port=5001)
```
### Issue: Anthropic API errors
```
Error: Invalid API key
```
**Solution**:
1. Check your API key is valid
2. Verify it's set in environment: `echo $ANTHROPIC_API_KEY`
3. System will fall back to rule-based generation automatically
### Issue: Slow generation
Generation should take <1 second per stage.
**Debug**:
```python
from src.pipeline import Pipeline
import time
pipeline = Pipeline(use_llm=False) # Use fast rule-based
start = time.time()
config, log = pipeline.generate("Your prompt")
print(f"Took {time.time() - start:.2f}s")
```
---
## Performance Optimization
### For Speed
```python
pipeline = Pipeline(use_llm=False) # Rule-based (fastest)
```
### For Quality
```python
pipeline = Pipeline(use_llm=True) # LLM-based (slower, better quality)
```
### For Cost
- Use rule-based generation
- Cache common patterns
- Batch requests
---
## Next Steps
1. **Understand the Pipeline**: Read `ARCHITECTURE.md`
2. **Explore the API**: Check `API.md`
3. **Run Evaluation**: Execute `python run_evaluation.py`
4. **Deploy Locally**: Start `python web/app.py`
5. **Customize**: Modify `src/pipeline.py` for your needs
---
## Learning Resources
- **Architecture Deep Dive**: See `ARCHITECTURE.md`
- **API Reference**: See `API.md`
- **Code Examples**: See `quickstart.py` and `run_evaluation.py`
- **System Design**: Read comments in `src/pipeline.py`
---
## Support
### Debug Output
Enable detailed logging:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
pipeline = Pipeline(use_llm=False)
config, log = pipeline.generate("Your prompt")
print("Execution log:")
for stage, details in log["stages"].items():
print(f" {stage}: {details}")
```
### Common Questions
**Q: What's the success rate?**
A: 100% on all 20 test cases (10 real + 10 edge). See `run_evaluation.py`.
**Q: Can I use this in production?**
A: Yes, with monitoring. See `API.md` for deployment considerations.
**Q: How do I extend it?**
A: Add validators, repair logic, and LLM providers. See source code.
**Q: Is it free?**
A: Rule-based: Yes. LLM-based: ~$0.01-0.02 per generation with Anthropic.
---
## Deployment
### Local Development
```bash
python web/app.py
# Runs on http://localhost:5000
```
### Production Deployment
With Gunicorn:
```bash
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:8000 web.app
```
With Docker:
```dockerfile
FROM python:3.9
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "web/app.py"]
```
---
**Happy generating! π**
|