File size: 1,517 Bytes
a39d8ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dca1644
a39d8ef
 
 
 
 
 
 
 
 
 
 
 
5a70e49
 
25575d3
 
 
85fc0ff
 
a069777
 
 
 
 
 
 
85fc0ff
 
 
25575d3
5a70e49
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
nl2sql-bench/server/app.py
============================
FastAPI application entry point for the NL2SQL-Bench OpenEnv server.

create_fastapi_app() auto-creates all required OpenEnv endpoints:
  POST /reset   β€” start a new episode
  POST /step    β€” submit an action
  GET  /state   β€” retrieve episode state
  GET  /health  β€” health check
  GET  /web     β€” interactive web UI (if ENABLE_WEB_INTERFACE=true)
  GET  /docs    β€” Swagger UI
"""

import sys
from pathlib import Path
from openenv.core.env_server import create_fastapi_app
from environment import NL2SQLEnvironment
import sqlite3 # <-- Add this import

# Ensure models can be imported from the parent directory
_HERE = Path(__file__).parent
sys.path.insert(0, str(_HERE.parent))

from models import NL2SQLAction, NL2SQLObservation

# Pass the explicitly required action and observation classes
app = create_fastapi_app(
    NL2SQLEnvironment,
    action_cls=NL2SQLAction,
    observation_cls=NL2SQLObservation
)

@app.on_event("startup")
async def startup_event():
    from db.seed import seed_database
    
    conn = sqlite3.connect('ecommerce.db')
    
    # NEW FIX: Read and execute the schema DDL first!
    with open('db/schema.sql', 'r') as f:
        schema_sql = f.read()
    conn.executescript(schema_sql)
    
    # Now that tables exist, insert the data
    seed_database(conn)
    conn.commit()
    conn.close()

def main():
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)

if __name__ == '__main__':
    main()