Rithwik Ravi commited on
Commit ·
a2db70a
1
Parent(s): bfcdfad
Fixed submission errors
Browse files- server/__pycache__/app.cpython-314.pyc +0 -0
- server/app.py +17 -6
- tmp_env.db +0 -0
server/__pycache__/app.cpython-314.pyc
CHANGED
|
Binary files a/server/__pycache__/app.cpython-314.pyc and b/server/__pycache__/app.cpython-314.pyc differ
|
|
|
server/app.py
CHANGED
|
@@ -8,6 +8,7 @@ from typing import Dict, Any, Optional
|
|
| 8 |
from fastapi import FastAPI, HTTPException, Request, Depends
|
| 9 |
from fastapi.responses import JSONResponse
|
| 10 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
|
|
| 11 |
from pydantic import BaseModel
|
| 12 |
import uvicorn
|
| 13 |
|
|
@@ -61,6 +62,11 @@ async def verify_auth_and_rate_limit(credentials: HTTPAuthorizationCredentials =
|
|
| 61 |
app = FastAPI(title="OpenEnv SQL Data Engineer")
|
| 62 |
db_semaphore = asyncio.Semaphore(5)
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
@app.middleware("http")
|
| 65 |
async def security_middleware(request: Request, call_next):
|
| 66 |
# Max payload limit ~ 1MB
|
|
@@ -73,9 +79,6 @@ async def security_middleware(request: Request, call_next):
|
|
| 73 |
return response
|
| 74 |
except asyncio.TimeoutError:
|
| 75 |
return JSONResponse(status_code=504, content={"error": "Gateway Timeout"})
|
| 76 |
-
except Exception as e:
|
| 77 |
-
logger.error(f"Unhandled exception: {str(e)}")
|
| 78 |
-
return JSONResponse(status_code=500, content={"error": "Internal Server Error"})
|
| 79 |
|
| 80 |
class SQLEnvironment:
|
| 81 |
def __init__(self):
|
|
@@ -246,11 +249,19 @@ class ResetRequest(BaseModel):
|
|
| 246 |
task_id: int = 1
|
| 247 |
|
| 248 |
@app.post("/reset", response_model=ResetResult)
|
| 249 |
-
async def reset(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
async with db_semaphore:
|
| 251 |
try:
|
| 252 |
-
logger.info(f"Resetting environment for task_id: {
|
| 253 |
-
return env_instance.reset(task_id=
|
| 254 |
except Exception as e:
|
| 255 |
logger.error(f"Reset Error: {str(e)}")
|
| 256 |
raise HTTPException(status_code=400, detail="Error during reset")
|
|
|
|
| 8 |
from fastapi import FastAPI, HTTPException, Request, Depends
|
| 9 |
from fastapi.responses import JSONResponse
|
| 10 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 11 |
+
from starlette.exceptions import HTTPException as StarletteHTTPException
|
| 12 |
from pydantic import BaseModel
|
| 13 |
import uvicorn
|
| 14 |
|
|
|
|
| 62 |
app = FastAPI(title="OpenEnv SQL Data Engineer")
|
| 63 |
db_semaphore = asyncio.Semaphore(5)
|
| 64 |
|
| 65 |
+
@app.exception_handler(Exception)
|
| 66 |
+
async def global_exception_handler(request: Request, exc: Exception):
|
| 67 |
+
logger.error(f"Unhandled exception: {str(exc)}")
|
| 68 |
+
return JSONResponse(status_code=500, content={"error": "Internal Server Error"})
|
| 69 |
+
|
| 70 |
@app.middleware("http")
|
| 71 |
async def security_middleware(request: Request, call_next):
|
| 72 |
# Max payload limit ~ 1MB
|
|
|
|
| 79 |
return response
|
| 80 |
except asyncio.TimeoutError:
|
| 81 |
return JSONResponse(status_code=504, content={"error": "Gateway Timeout"})
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
class SQLEnvironment:
|
| 84 |
def __init__(self):
|
|
|
|
| 249 |
task_id: int = 1
|
| 250 |
|
| 251 |
@app.post("/reset", response_model=ResetResult)
|
| 252 |
+
async def reset(request: Request):
|
| 253 |
+
task_id = 1
|
| 254 |
+
try:
|
| 255 |
+
data = await request.json()
|
| 256 |
+
if "task_id" in data:
|
| 257 |
+
task_id = int(data["task_id"])
|
| 258 |
+
except:
|
| 259 |
+
pass # gracefully handle missing json body (curl -d '{}')
|
| 260 |
+
|
| 261 |
async with db_semaphore:
|
| 262 |
try:
|
| 263 |
+
logger.info(f"Resetting environment for task_id: {task_id}")
|
| 264 |
+
return env_instance.reset(task_id=task_id)
|
| 265 |
except Exception as e:
|
| 266 |
logger.error(f"Reset Error: {str(e)}")
|
| 267 |
raise HTTPException(status_code=400, detail="Error during reset")
|
tmp_env.db
CHANGED
|
Binary files a/tmp_env.db and b/tmp_env.db differ
|
|
|