Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- .gitignore +3 -0
- Dockerfile +1 -1
- out.txt +1 -0
- pyproject.toml +19 -0
- server/Dockerfile +1 -1
- server/app.py +118 -0
- uv.lock +0 -0
- validate_out.txt +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
*/__pycache__/*
|
| 3 |
+
*/server/tasks/__pycache__
|
Dockerfile
CHANGED
|
@@ -9,4 +9,4 @@ COPY server/ .
|
|
| 9 |
|
| 10 |
# Expose port and run uvicorn
|
| 11 |
EXPOSE 7860
|
| 12 |
-
CMD ["uvicorn", "
|
|
|
|
| 9 |
|
| 10 |
# Expose port and run uvicorn
|
| 11 |
EXPOSE 7860
|
| 12 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
out.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[OK] : Ready for multi-mode deployment
|
pyproject.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["setuptools>=61.0"]
|
| 3 |
+
build-backend = "setuptools.build_meta"
|
| 4 |
+
|
| 5 |
+
[project]
|
| 6 |
+
name = "sql-debug-env"
|
| 7 |
+
version = "1.0.0"
|
| 8 |
+
description = "OpenENV SQL Query Debugging Environment"
|
| 9 |
+
readme = "README.md"
|
| 10 |
+
requires-python = ">=3.11"
|
| 11 |
+
dependencies = [
|
| 12 |
+
"fastapi>=0.110.0",
|
| 13 |
+
"uvicorn[standard]>=0.29.0",
|
| 14 |
+
"pydantic>=2.0.0",
|
| 15 |
+
"openenv-core>=0.2.0"
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
[project.scripts]
|
| 19 |
+
server = "server.app:main"
|
server/Dockerfile
CHANGED
|
@@ -9,4 +9,4 @@ COPY . .
|
|
| 9 |
|
| 10 |
EXPOSE 7860
|
| 11 |
|
| 12 |
-
CMD ["uvicorn", "
|
|
|
|
| 9 |
|
| 10 |
EXPOSE 7860
|
| 11 |
|
| 12 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
server/app.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
FastAPI server exposing the OpenENV SQL Debugging environment.
|
| 3 |
+
|
| 4 |
+
Endpoints:
|
| 5 |
+
POST /reset?task=<name> → SQLObservation (reset with optional task selection)
|
| 6 |
+
POST /step → StepResult (submit SQLAction, get StepResult)
|
| 7 |
+
GET /state → SQLObservation (current state, no side effects)
|
| 8 |
+
GET /health → {"status":"ok"} (liveness probe)
|
| 9 |
+
"""
|
| 10 |
+
from fastapi import FastAPI, HTTPException, Query
|
| 11 |
+
from fastapi.responses import JSONResponse
|
| 12 |
+
|
| 13 |
+
from models import SQLAction, SQLObservation, StepResult
|
| 14 |
+
from env import SQLEnvironment
|
| 15 |
+
|
| 16 |
+
app = FastAPI(
|
| 17 |
+
title="OpenENV — SQL Debugging Environment",
|
| 18 |
+
description=(
|
| 19 |
+
"An OpenEnv-compliant RL environment where an AI agent debugs and fixes "
|
| 20 |
+
"broken SQL queries against an in-memory SQLite database."
|
| 21 |
+
),
|
| 22 |
+
version="1.0.0",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Single global environment instance (one agent at a time)
|
| 26 |
+
_env = SQLEnvironment()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# ---------------------------------------------------------------------------
|
| 30 |
+
# /health
|
| 31 |
+
# ---------------------------------------------------------------------------
|
| 32 |
+
|
| 33 |
+
@app.get("/health", summary="Liveness probe")
|
| 34 |
+
def health():
|
| 35 |
+
"""Returns 200 OK with status=ok if the server is running."""
|
| 36 |
+
return {"status": "ok"}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# ---------------------------------------------------------------------------
|
| 40 |
+
# /reset
|
| 41 |
+
# ---------------------------------------------------------------------------
|
| 42 |
+
|
| 43 |
+
VALID_TASKS = ["fix-syntax", "fix-logic", "fix-and-optimize"]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@app.post("/reset", response_model=SQLObservation, summary="Reset the environment")
|
| 47 |
+
def reset(
|
| 48 |
+
task: str = Query(
|
| 49 |
+
default="fix-syntax",
|
| 50 |
+
description="Task name. One of: fix-syntax, fix-logic, fix-and-optimize",
|
| 51 |
+
)
|
| 52 |
+
):
|
| 53 |
+
"""
|
| 54 |
+
Reset the environment with the specified task and return the initial observation.
|
| 55 |
+
If no task is provided, defaults to 'fix-syntax'.
|
| 56 |
+
"""
|
| 57 |
+
if task not in VALID_TASKS:
|
| 58 |
+
raise HTTPException(
|
| 59 |
+
status_code=400,
|
| 60 |
+
detail=f"Invalid task '{task}'. Must be one of: {VALID_TASKS}",
|
| 61 |
+
)
|
| 62 |
+
try:
|
| 63 |
+
obs = _env.reset(task_name=task)
|
| 64 |
+
return obs
|
| 65 |
+
except ValueError as exc:
|
| 66 |
+
raise HTTPException(status_code=400, detail=str(exc))
|
| 67 |
+
except RuntimeError as exc:
|
| 68 |
+
raise HTTPException(status_code=500, detail=str(exc))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# ---------------------------------------------------------------------------
|
| 72 |
+
# /step
|
| 73 |
+
# ---------------------------------------------------------------------------
|
| 74 |
+
|
| 75 |
+
@app.post("/step", response_model=StepResult, summary="Submit an action")
|
| 76 |
+
def step(action: SQLAction):
|
| 77 |
+
"""
|
| 78 |
+
Submit a SQL query as the agent's action. Returns a StepResult with
|
| 79 |
+
the new observation, reward, done flag, and info dict.
|
| 80 |
+
"""
|
| 81 |
+
try:
|
| 82 |
+
result = _env.step(action)
|
| 83 |
+
return result
|
| 84 |
+
except RuntimeError as exc:
|
| 85 |
+
raise HTTPException(status_code=400, detail=str(exc))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
# ---------------------------------------------------------------------------
|
| 89 |
+
# /state
|
| 90 |
+
# ---------------------------------------------------------------------------
|
| 91 |
+
|
| 92 |
+
@app.get("/state", response_model=SQLObservation, summary="Get current state")
|
| 93 |
+
def state():
|
| 94 |
+
"""
|
| 95 |
+
Return the current observation without advancing the episode.
|
| 96 |
+
Useful for agents that need to re-read the environment state.
|
| 97 |
+
"""
|
| 98 |
+
try:
|
| 99 |
+
obs = _env.state()
|
| 100 |
+
return obs
|
| 101 |
+
except RuntimeError as exc:
|
| 102 |
+
raise HTTPException(status_code=400, detail=str(exc))
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# ---------------------------------------------------------------------------
|
| 106 |
+
# Root redirect → docs
|
| 107 |
+
# ---------------------------------------------------------------------------
|
| 108 |
+
|
| 109 |
+
@app.get("/", include_in_schema=False)
|
| 110 |
+
def root():
|
| 111 |
+
return JSONResponse({"message": "OpenENV SQL Debugging Environment. See /docs for API reference."})
|
| 112 |
+
|
| 113 |
+
def main():
|
| 114 |
+
import uvicorn
|
| 115 |
+
uvicorn.run("server.app:app", host="0.0.0.0", port=7860)
|
| 116 |
+
|
| 117 |
+
if __name__ == "__main__":
|
| 118 |
+
main()
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
validate_out.txt
ADDED
|
Binary file (534 Bytes). View file
|
|
|