File size: 1,772 Bytes
aa3a171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5db060f
aa3a171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""
FastAPI server for the SQL Debug & Optimizer Environment.

Exposes the environment over HTTP + WebSocket so inference.py
(and the OpenEnv evaluator) can interact with it remotely.

Endpoints created automatically by openenv:
    POST /reset    β€” start new episode (optionally pass task_id in body)
    POST /step     β€” submit an action, get observation + reward
    GET  /state    β€” current episode state
    GET  /schema   β€” action/observation JSON schemas
    WS   /ws       β€” WebSocket for persistent low-latency sessions

Run locally:
    uvicorn server.app:app --host 0.0.0.0 --port 8000 --reload

Or via Docker (defined in Dockerfile):
    docker build -t sql-debug-env .
    docker run -p 8000:8000 sql-debug-env
"""

try:
    from openenv.core.env_server.http_server import create_app
except Exception as e:
    raise ImportError(
        "openenv-core is required. Install with: pip install openenv-core"
    ) from e

try:
    from models import SQLDebugAction, SQLDebugObservation
    from .sql_debug_environment import SQLDebugEnvironment
except ModuleNotFoundError:
    from models import SQLDebugAction, SQLDebugObservation
    from server.sql_debug_environment import SQLDebugEnvironment


app = create_app(
    SQLDebugEnvironment,
    SQLDebugAction,
    SQLDebugObservation,
    env_name="sql_debug_optimizer",
    max_concurrent_envs=4,   # one per task running in parallel
)


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


if __name__ == "__main__":
    main()