ritvik360/nl2sql-bench
0
1"""2nl2sql-bench/server/app.py3============================4FastAPI application entry point for the NL2SQL-Bench OpenEnv server.5 6create_fastapi_app() auto-creates all required OpenEnv endpoints:7 POST /reset — start a new episode8 POST /step — submit an action9 GET /state — retrieve episode state10 GET /health — health check11 GET /web — interactive web UI (if ENABLE_WEB_INTERFACE=true)12 GET /docs — Swagger UI13"""14 15import sys16from pathlib import Path17from openenv.core.env_server import create_fastapi_app18from environment import NL2SQLEnvironment19import sqlite3 # <-- Add this import20 21# Ensure models can be imported from the parent directory22_HERE = Path(__file__).parent23sys.path.insert(0, str(_HERE.parent))24 25from models import NL2SQLAction, NL2SQLObservation26 27# Pass the explicitly required action and observation classes28app = create_fastapi_app(29 NL2SQLEnvironment,30 action_cls=NL2SQLAction,31 observation_cls=NL2SQLObservation32)33 34@app.on_event("startup")35async def startup_event():36 from db.seed import seed_database37 38 conn = sqlite3.connect('ecommerce.db')39 40 # NEW FIX: Read and execute the schema DDL first!41 with open('db/schema.sql', 'r') as f:42 schema_sql = f.read()43 conn.executescript(schema_sql)44 45 # Now that tables exist, insert the data46 seed_database(conn)47 conn.commit()48 conn.close()49 50def main():51 import uvicorn52 uvicorn.run(app, host="0.0.0.0", port=7860)53 54if __name__ == '__main__':55 main()