Views
No views yet
1# 1. Clone
2git clone https://github.com/<you>/codedebug-env
3cd codedebug-env
4
5# 2. Install
6pip install -r requirements.txt
7
8# 3. Run the server
9python app.py
10# → http://localhost:7860/docs
11
12# 4. Smoke-test
13curl http://localhost:7860/api/v1/health
14curl -X POST http://localhost:7860/reset -H "Content-Type: application/json" -d "{}"codedebug-env/
├── src/
│ └── openenv_env/
│ ├── __init__.py # public API
│ ├── models.py # Pydantic Action / Observation / StepResult
│ ├── tasks.py # TaskSpec registry (7 tasks)
│ ├── graders.py # 5 graders; composite reward in [0,1]
│ ├── environment.py # CodeDebugEnvironment (reset/step/state)
│ └── server.py # FastAPI app via create_app()
├── course/
│ ├── index.md
│ ├── module_01_intro/ README.md + notebook.ipynb
│ ├── module_02_environment/ README.md + notebook.ipynb
│ ├── module_03_inference/ README.md + notebook.ipynb
│ ├── module_04_graders/ README.md + notebook.ipynb
│ └── module_05_deployment/ README.md + notebook.ipynb
├── inference.py # LLM agent evaluation harness
├── validate_submission.py # Pre-submission validator
├── app.py # Docker entrypoint
├── manifest.json # OpenEnv manifest
├── Dockerfile
├── pyproject.toml
├── requirements.txt
└── README.md1pip install -e ".[dev]"
2uvicorn openenv_env.server:create_app --factory --port 8000 --reload1python app.py # uses PORT env var (default 7860)
2PORT=8080 python app.py # custom port1# Build
2docker build -t codedebug-env:latest .
3
4# Run
5docker run -p 7860:7860 codedebug-env:latest
6
7# Run with inference env vars
8docker run -p 7860:7860 \
9 -e API_BASE_URL=https://api.openai.com/v1 \
10 -e MODEL_NAME=gpt-4o-mini \
11 -e HF_TOKEN=hf_your_token_here \
12 codedebug-env:latest
13
14# Confirm it is up
15curl http://localhost:7860/api/v1/health1curl -X POST http://localhost:7860/reset \
2 -H "Content-Type: application/json" \
3 -d '{}'1curl -X POST http://localhost:7860/reset \
2 -H "Content-Type: application/json" \
3 -d '{"task_id": "task_syntax_001"}'1{
2 "task_id": "task_syntax_001",
3 "step": 0,
4 "buggy_code": "def multiply(a, b)\n result = a * b\n return result\n",
5 "error_message": "SyntaxError: expected ':'",
6 "error_type": "syntax",
7 "difficulty": "easy",
8 "max_steps": 3,
9 "hints": [],
10 "done": false,
11 "reward": 0.0,
12 "metadata": {"description": "Fix a missing colon in a function definition."}
13}1curl -X POST http://localhost:7860/step \
2 -H "Content-Type: application/json" \
3 -d '{
4 "action": {
5 "fixed_code": "def multiply(a, b):\n result = a * b\n return result\n",
6 "explanation": "Added the missing colon after the function signature.",
7 "confidence": 0.95
8 }
9 }'1{
2 "observation": {"task_id": "task_syntax_001", "step": 1, "done": true, ...},
3 "reward": 0.9553,
4 "done": true,
5 "info": {"solved": true, "timeout": false, "step_reward": 0.9553, "cumulative_reward": 0.9553}
6}curl http://localhost:7860/state1curl http://localhost:7860/api/v1/health
2# {"status": "ok", "uptime_seconds": 12.4, "version": "1.0.0", ...}1# Reset
2curl -X POST http://localhost:7860/api/v1/reset -H "Content-Type: application/json" -d '{}'
3
4# Step
5curl -X POST http://localhost:7860/api/v1/step \
6 -H "Content-Type: application/json" \
7 -d '{"action": {"fixed_code": "def f(x):\n return x\n", "explanation": "test"}}'
8
9# State
10curl http://localhost:7860/api/v1/state| Variable | Required | Description | Example |
|---|---|---|---|
API_BASE_URL | Yes | OpenAI-compatible base URL | https://api.openai.com/v1 |
MODEL_NAME | Yes | Model identifier | gpt-4o-mini |
HF_TOKEN | Optional | HF token (used as API key for HF Inference) | hf_xxx... |
1# Set env vars
2export API_BASE_URL=https://api.openai.com/v1
3export MODEL_NAME=gpt-4o-mini
4export OPENAI_API_KEY=sk-your-key-here # or HF_TOKEN
5
6# Run all default tasks (first 3)
7python inference.py
8
9# Run specific tasks
10python inference.py --tasks task_syntax_001 task_logic_001 task_runtime_001
11
12# With verbose output + save results
13python inference.py --tasks task_syntax_001 --verbose --output results.json
14
15# Override max steps (useful for quick tests)
16python inference.py --max-steps 1
17
18# Using Hugging Face Inference Endpoint
19export API_BASE_URL=https://api-inference.huggingface.co/models/meta-llama/Llama-3.3-70B-Instruct/v1
20export MODEL_NAME=meta-llama/Llama-3.3-70B-Instruct
21export HF_TOKEN=hf_your_token_here
22python inference.py1{"tag": "[START]", "tasks": ["task_syntax_001"], "model": "gpt-4o-mini", "timestamp": 1700000000.0}
2{"tag": "[STEP]", "task_id": "task_syntax_001", "step": 1, "composite_score": 0.9553, "done": false}
3{"tag": "[END]", "total_tasks": 3, "solved": 2, "avg_best_score": 0.7812, "elapsed_seconds": 8.1}1python inference.py | jq 'select(.tag == "[END]")'
2python inference.py | jq 'select(.tag == "[STEP]") | .composite_score'1# Full validation (includes Docker build)
2python validate_submission.py
3
4# Minimal mode — skip Docker and HF Space checks
5python validate_submission.py --minimal
6
7# Skip only Docker
8python validate_submission.py --no-docker
9
10# Include HF Space URL ping
11python validate_submission.py --hf-url https://<username>-codedebug-env.hf.space
12
13# Verbose output
14python validate_submission.py --minimal --verbosehuggingface_hub installed: pip install huggingface_hubhuggingface-cli login1# 1. Create Space at https://huggingface.co/spaces (type: Docker)
2
3# 2. Add HF remote
4git remote add hf https://huggingface.co/spaces/<username>/codedebug-env
5
6# 3. Push
7git push hf main
8
9# 4. Monitor build logs in the Space UI
10
11# 5. Verify deployment
12curl https://<username>-codedebug-env.hf.space/api/v1/health1from huggingface_hub import HfApi
2
3api = HfApi()
4api.upload_folder(
5 folder_path=".",
6 repo_id="<username>/codedebug-env",
7 repo_type="space",
8 ignore_patterns=["*.pyc", "__pycache__", ".git", ".env"],
9)README.md header (add to top of README for Spaces)1---
2title: CodeDebug OpenEnv
3emoji: 🐛
4colorFrom: blue
5colorTo: green
6sdk: docker
7pinned: false
8---python validate_submission.py --minimal → all checks passpython inference.py --max-steps 1 → emits [START], [STEP], [END]docker build -t codedebug-env . → exits 0docker run -p 7860:7860 codedebug-env starts and /health returns 200manifest.json present with all required keysTASK_REGISTRYGRADER_REGISTRY[0.0, 1.0]/api/v1/healthREADME.md complete with quickstart instructionsgit status is clean (no uncommitted changes)course/:| Module | Topic |
|---|---|
| 01 — Intro to OpenEnv | Lifecycle, manifest, core concepts |
| 02 — Environment Design | Tasks, typed models, grader architecture |
| 03 — LLM Inference | OpenAI client, env vars, structured logs |
| 04 — Grader Engineering | Reward shaping, custom graders |
| 05 — Deployment | Docker, HF Spaces, CI |
README.md (concepts) and notebook.ipynb (hands-on exercises).