CoolFace
Apppublic

fablefrost/Project1

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
App README

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

  1. 1.Clone and setup:
bash
   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
  1. 1.Configure environment:
bash
   cp .env.example .env
   # Edit .env with your actual values
  1. 1.Setup GitHub CLI:
bash
   gh auth login
   gh auth status

Required Environment Variables

env
# 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,secret2,secret3

๐Ÿš€ Usage

Start the API

bash
python app.py

The API will be available at http://localhost:5000

API Endpoints

  • โ€”POST /api - Submit deployment request
  • โ€”GET /health - Health check
  • โ€”GET / - API information

Request Format

json
{
  "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

bash
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)

  1. 1.Receive JSON request with brief and attachments
  2. 2.Validate secret and required fields
  3. 3.Use LLM to generate project files (HTML, CSS, JS)
  4. 4.Create new GitHub repository
  5. 5.Push generated code and enable GitHub Pages
  6. 6.Notify evaluation endpoint with deployment URLs

Round 2 (Revise Phase)

  1. 1.Receive revision request with new requirements
  2. 2.Use LLM to modify existing project
  3. 3.Update GitHub repository with changes
  4. 4.Notify evaluation endpoint with updated URLs

๐Ÿงช Testing

Run Tests

bash
python -m pytest tests/ -v

Manual Testing

bash
# Test the health endpoint
curl http://localhost:5000/health

# Test with sample data
python tests/test_manual.py

Example Test Request

python
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

VariableDescriptionDefault
MAX_DEPLOYMENT_TIMEMax deployment time (seconds)600
RETRY_ATTEMPTSEvaluation endpoint retries5
LLM_MODELOpenAI model to usegpt-4o-mini
PAGES_BRANCHGitHub Pages branchmain
PAGES_SOURCEGitHub Pages source/

๐Ÿ› Troubleshooting

Common Issues

  1. 1.GitHub CLI not authenticated:
bash
   gh auth login
   gh auth status
  1. 1.OpenAI API errors:
  2. 2.Check API key validity
  3. 3.Verify API credit/usage limits
  4. 4.Ensure base URL is correct
  1. 1.Repository creation fails:
  2. 2.Verify GitHub token permissions
  3. 3.Check if repository name already exists
  4. 4.Ensure GitHub username/org is correct
  1. 1.Pages deployment issues:
  2. 2.GitHub Pages may take a few minutes to activate
  3. 3.Check repository settings for Pages configuration
  4. 4.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

dockerfile
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

  1. 1.Set environment variables in platform dashboard
  2. 2.Ensure PORT variable is respected (already handled in app.py)
  3. 3.Install GitHub CLI in deployment environment

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes with tests
  4. 4.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.