CoolFace
Apppublic

2008robocode-crypto/code-generation-system

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
GETTING_STARTED.md405 linesDownload Raw Back to root
1# Getting Started Guide2 3## Quick Start (5 minutes)4 5### 1. Install Dependencies6 7```bash8cd "ai intern project"9pip install -r requirements.txt10```11 12### 2. Run Demo13 14```bash15python quickstart.py16```17 18You should see output like:19```20๐Ÿค– AI PLATFORM ENGINEER - CODE GENERATION SYSTEM21โœ“ Generation Status: success22โœ“ Executable: YES โœ“23โœ“ Database Tables: 324โœ“ API Endpoints: 1525```26 27### 3. Try the Web Interface28 29```bash30python web/app.py31```32 33Open your browser: **http://localhost:5000**34 35- Enter a prompt in the input box36- Click "Generate Configuration"37- See the JSON output with validation report38 39---40 41## Installation Details42 43### Requirements44- Python 3.8+45- pip (Python package manager)46 47### Step-by-Step Setup48 49#### 1. Create Virtual Environment (Optional but Recommended)50 51```bash52# Windows53python -m venv venv54venv\Scripts\activate55 56# Linux/Mac57python3 -m venv venv58source venv/bin/activate59```60 61#### 2. Install Dependencies62 63```bash64pip install -r requirements.txt65```66 67This installs:68- `flask` - Web framework69- `flask-cors` - Cross-origin support70- `anthropic` - LLM API (optional)71- `python-dotenv` - Environment variables72 73#### 3. (Optional) Set Up Anthropic API74 75For LLM-powered generation (optional):76 77```bash78# Windows79set ANTHROPIC_API_KEY=your-key-here80 81# Linux/Mac82export ANTHROPIC_API_KEY=your-key-here83```84 85Or create `.env` file:86```87ANTHROPIC_API_KEY=your-key-here88```89 90---91 92## Usage Modes93 94### Mode 1: Quick Start Demo95 96Generate 3 example configurations:97 98```bash99python quickstart.py100```101 102**Output**: Demonstrates pipeline stages and validation103 104---105 106### Mode 2: Web Interface107 108Interactive UI for generation:109 110```bash111python web/app.py112```113 114**Features**:115- Enter natural language prompts116- Real-time JSON output117- Validation reports118- Example generation119 120**Access**: http://localhost:5000121 122---123 124### Mode 3: Evaluation Framework125 126Run comprehensive tests (20 prompts):127 128```bash129python run_evaluation.py130```131 132**Output**:133- Success rates (100% in current version)134- Performance metrics135- Cost analysis136- JSON report saved to `evaluation_report_*.json`137 138---139 140### Mode 4: Python Library141 142Use the system programmatically:143 144```python145from src.pipeline import Pipeline146from src.runtime_simulator import validate_config_executable147 148# Initialize149pipeline = Pipeline(use_llm=False)  # Rule-based150# pipeline = Pipeline(use_llm=True)  # LLM-based (requires API key)151 152# Generate153prompt = "Build a CRM with login, contacts, dashboard"154config, exec_log = pipeline.generate(prompt)155 156# Validate157is_executable, report = validate_config_executable(config)158 159print(f"Success: {exec_log['final_status']}")160print(f"Executable: {is_executable}")161```162 163---164 165## Project Structure166 167```168ai intern project/169โ”œโ”€โ”€ src/170โ”‚   โ”œโ”€โ”€ schemas.py           # Data structures171โ”‚   โ”œโ”€โ”€ pipeline.py          # Main 4-stage pipeline172โ”‚   โ”œโ”€โ”€ validator.py         # Validation engine173โ”‚   โ”œโ”€โ”€ repair_engine.py     # Repair system174โ”‚   โ””โ”€โ”€ runtime_simulator.py # Executability checks175โ”‚176โ”œโ”€โ”€ web/177โ”‚   โ”œโ”€โ”€ app.py              # Flask API server178โ”‚   โ”œโ”€โ”€ templates/179โ”‚   โ”‚   โ””โ”€โ”€ index.html      # Web interface180โ”‚   โ””โ”€โ”€ static/             # Assets (CSS, JS)181โ”‚182โ”œโ”€โ”€ evaluation/183โ”‚   โ”œโ”€โ”€ test_dataset.py     # 20 test prompts184โ”‚   โ””โ”€โ”€ evaluator.py        # Evaluation framework185โ”‚186โ”œโ”€โ”€ quickstart.py           # Demo script187โ”œโ”€โ”€ run_evaluation.py       # Evaluation runner188โ”œโ”€โ”€ requirements.txt        # Dependencies189โ”œโ”€โ”€ README.md              # Main documentation190โ”œโ”€โ”€ ARCHITECTURE.md        # System design191โ”œโ”€โ”€ API.md                 # API documentation192โ””โ”€โ”€ GETTING_STARTED.md     # This file193```194 195---196 197## Common Tasks198 199### Generate a Configuration200 201**Option 1: Via Web UI**2021. Open http://localhost:50002032. Enter your prompt2043. Click "Generate"2054. See JSON output206 207**Option 2: Via API**208```bash209curl -X POST http://localhost:5000/api/generate \210  -H "Content-Type: application/json" \211  -d '{"prompt":"Build a todo app"}'212```213 214**Option 3: Via Python**215```python216from src.pipeline import Pipeline217 218pipeline = Pipeline()219config, log = pipeline.generate("Build a todo app")220```221 222### Check System Status223 224```bash225# Web interface226curl http://localhost:5000/api/health227 228# Quick demo229python quickstart.py230 231# Full evaluation232python run_evaluation.py233```234 235### Customize the System236 237**Edit intent extraction patterns**: `src/pipeline.py` โ†’ `IntentExtractor`238 239**Add new validation rules**: `src/validator.py` โ†’ `Validator`240 241**Modify repair logic**: `src/repair_engine.py` โ†’ `RepairEngine`242 243**Add test prompts**: `evaluation/test_dataset.py` โ†’ `TEST_PROMPTS`244 245---246 247## Troubleshooting248 249### Issue: Module not found error250 251```252ModuleNotFoundError: No module named 'flask'253```254 255**Solution**:256```bash257pip install -r requirements.txt258```259 260### Issue: Port 5000 already in use261 262```263Address already in use264```265 266**Solution**:267```bash268# Option 1: Kill the process using port 5000269# Windows270netstat -ano | findstr :5000271taskkill /PID <PID> /F272 273# Option 2: Use different port in app.py274app.run(port=5001)275```276 277### Issue: Anthropic API errors278 279```280Error: Invalid API key281```282 283**Solution**:2841. Check your API key is valid2852. Verify it's set in environment: `echo $ANTHROPIC_API_KEY`2863. System will fall back to rule-based generation automatically287 288### Issue: Slow generation289 290Generation should take <1 second per stage.291 292**Debug**:293```python294from src.pipeline import Pipeline295import time296 297pipeline = Pipeline(use_llm=False)  # Use fast rule-based298start = time.time()299config, log = pipeline.generate("Your prompt")300print(f"Took {time.time() - start:.2f}s")301```302 303---304 305## Performance Optimization306 307### For Speed308```python309pipeline = Pipeline(use_llm=False)  # Rule-based (fastest)310```311 312### For Quality313```python314pipeline = Pipeline(use_llm=True)   # LLM-based (slower, better quality)315```316 317### For Cost318- Use rule-based generation319- Cache common patterns320- Batch requests321 322---323 324## Next Steps325 3261. **Understand the Pipeline**: Read `ARCHITECTURE.md`3272. **Explore the API**: Check `API.md`3283. **Run Evaluation**: Execute `python run_evaluation.py`3294. **Deploy Locally**: Start `python web/app.py`3305. **Customize**: Modify `src/pipeline.py` for your needs331 332---333 334## Learning Resources335 336- **Architecture Deep Dive**: See `ARCHITECTURE.md`337- **API Reference**: See `API.md`338- **Code Examples**: See `quickstart.py` and `run_evaluation.py`339- **System Design**: Read comments in `src/pipeline.py`340 341---342 343## Support344 345### Debug Output346 347Enable detailed logging:348 349```python350import logging351logging.basicConfig(level=logging.DEBUG)352 353pipeline = Pipeline(use_llm=False)354config, log = pipeline.generate("Your prompt")355 356print("Execution log:")357for stage, details in log["stages"].items():358    print(f"  {stage}: {details}")359```360 361### Common Questions362 363**Q: What's the success rate?**364A: 100% on all 20 test cases (10 real + 10 edge). See `run_evaluation.py`.365 366**Q: Can I use this in production?**367A: Yes, with monitoring. See `API.md` for deployment considerations.368 369**Q: How do I extend it?**370A: Add validators, repair logic, and LLM providers. See source code.371 372**Q: Is it free?**373A: Rule-based: Yes. LLM-based: ~$0.01-0.02 per generation with Anthropic.374 375---376 377## Deployment378 379### Local Development380```bash381python web/app.py382# Runs on http://localhost:5000383```384 385### Production Deployment386 387With Gunicorn:388```bash389pip install gunicorn390gunicorn -w 4 -b 0.0.0.0:8000 web.app391```392 393With Docker:394```dockerfile395FROM python:3.9396WORKDIR /app397COPY . .398RUN pip install -r requirements.txt399CMD ["python", "web/app.py"]400```401 402---403 404**Happy generating! ๐Ÿš€**405