fablefrost/TDS_Project1
0
LLM Code Deployment API
๐ An automated system that builds, deploys, and revises web applications based on JSON task requests using AI.
This API accepts JSON briefs with attachments, uses Large Language Models to generate project code, deploys to GitHub repositories with Pages enabled, and notifies evaluation endpoints.
๐ฏ Features
- Build Phase: Generate complete web projects from text briefs
- Revise Phase: Update existing projects with new requirements
- GitHub Integration: Automatic repo creation and GitHub Pages deployment
- LLM-Powered: Uses OpenAI API for intelligent code generation
- Retry Logic: Robust evaluation endpoint notification with exponential backoff
- Attachment Support: Handles base64-encoded file attachments
- Professional Output: Generates README, LICENSE, and clean project structure
๐ Project Structure
tdssep/
โโโ app.py # Main Flask application
โโโ src/
โ โโโ __init__.py
โ โโโ api_handler.py # Request processing logic
โ โโโ config.py # Configuration management
โ โโโ llm_generator.py # AI code generation
โ โโโ github_deployer.py # GitHub integration
โ โโโ evaluation_notifier.py # Endpoint notification
โ โโโ readme_generator.py # README creation
โ โโโ utils.py # Utility functions
โโโ tests/ # Test files
โโโ temp/ # Temporary file storage
โโโ logs/ # Request logs
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment template
โโโ README.md # This file๐ ๏ธ Setup
Prerequisites
- Python 3.8+
- Git
- GitHub CLI (
gh) installed and authenticated - OpenAI API access
Installation
- Clone and setup:
git clone <repository-url>
cd tdssep
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
pip install -r requirements.txt- Configure environment:
cp .env.example .env
# Edit .env with your actual values- Setup GitHub CLI:
gh auth login
gh auth statusRequired Environment Variables
# GitHub Integration
GITHUB_TOKEN=ghp_your_token_here
GITHUB_USERNAME=your-username
# OpenAI API
OPENAI_API_KEY=sk_your_key_here
# API Security
VALID_SECRETS=secret1๐ Usage
Start the API
python app.pyThe API will be available at http://localhost:5000
API Endpoints
POST /api- Submit deployment requestGET /health- Health checkGET /- API information
Request Format
{
"email": "student@example.com",
"secret": "your-valid-secret",
"task": "task-123",
"round": 1,
"nonce": "unique-request-id",
"brief": "Create a responsive todo list application with Bootstrap",
"evaluation_url": "https://evaluator.example.com/results",
"checks": ["Must have #add-task button", "Must display task count"],
"attachments": [
{
"filename": "data.csv",
"content": "base64-encoded-content"
}
]
}Example cURL Request
curl -X POST http://localhost:5000/api \
-H "Content-Type: application/json" \
-d '{
"email": "student@example.com",
"secret": "dev-secret-123",
"task": "todo-app",
"round": 1,
"nonce": "req-001",
"brief": "Create a todo list with add/remove functionality",
"evaluation_url": "https://webhook.site/your-unique-url"
}'๐ Workflow
Round 1 (Build Phase)
- Receive JSON request with brief and attachments
- Validate secret and required fields
- Use LLM to generate project files (HTML, CSS, JS)
- Create new GitHub repository
- Push generated code and enable GitHub Pages
- Notify evaluation endpoint with deployment URLs
Round 2 (Revise Phase)
- Receive revision request with new requirements
- Use LLM to modify existing project
- Update GitHub repository with changes
- Notify evaluation endpoint with updated URLs
๐งช Testing
Run Tests
python -m pytest tests/ -vManual Testing
# Test the health endpoint
curl http://localhost:5000/health
# Test with sample data
python tests/test_manual.pyExample Test Request
import requests
response = requests.post('http://localhost:5000/api', json={
"email": "test@example.com",
"secret": "dev-secret-123",
"task": "test-123",
"round": 1,
"nonce": "test-nonce",
"brief": "Create a simple calculator app",
"evaluation_url": "https://httpbin.org/post"
})
print(response.json())๐ Generated Project Features
Each deployed project includes:
- Responsive Design: Bootstrap 5 integration
- Clean Structure: Organized HTML, CSS, and JavaScript files
- Professional Documentation: Auto-generated README and LICENSE
- GitHub Pages Ready: Immediate deployment and hosting
- Error Handling: Robust client-side error management
- Accessibility: Semantic HTML and ARIA attributes
๐ง Configuration Options
๐ Troubleshooting
Common Issues
- GitHub CLI not authenticated:
gh auth login
gh auth status- OpenAI API errors:
- Check API key validity
- Verify API credit/usage limits
- Ensure base URL is correct
- Repository creation fails:
- Verify GitHub token permissions
- Check if repository name already exists
- Ensure GitHub username/org is correct
- Pages deployment issues:
- GitHub Pages may take a few minutes to activate
- Check repository settings for Pages configuration
- Verify branch and source path settings
Logs
Check the logs/ directory for detailed request logs and error information.
๐ Security
- API secrets are validated before processing
- GitHub tokens use minimal required permissions
- Request data is logged with sensitive fields redacted
- Input validation prevents malicious payloads
- Temporary files are cleaned up after use
๐ Deployment
Docker
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]Railway/Heroku
- Set environment variables in platform dashboard
- Ensure
PORTvariable is respected (already handled in app.py) - Install GitHub CLI in deployment environment
๐ License
MIT License - see LICENSE file for details.
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Submit a pull request
๐ Support
For issues and questions:
- Check the troubleshooting section
- Review logs in the
logs/directory - Open an issue on GitHub
This project provides automated code deployment capabilities using AI for educational and development purposes.
