Anushka-stack-queues/FinBench
0
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""8FastAPI application for the Finbench Environment.9 10This module creates an HTTP server that exposes the FinbenchEnvironment11over HTTP and WebSocket endpoints, compatible with EnvClient.12 13Endpoints:14 - POST /reset: Reset the environment15 - POST /step: Execute an action16 - GET /state: Get current environment state17 - GET /schema: Get action/observation schemas18 - WS /ws: WebSocket endpoint for persistent sessions19 20Usage:21 # Development (with auto-reload):22 uvicorn FinBench.server.app:app --reload --host 0.0.0.0 --port 800023 24 # Production:25 uvicorn FinBench.server.app:app --host 0.0.0.0 --port 8000 --workers 426 27 # Or run directly:28 python -m FinBench.server.app29"""30 31try:32 from openenv.core.env_server.http_server import create_app33except Exception as e: # pragma: no cover34 raise ImportError(35 "openenv is required for the web interface. Install dependencies with '\n uv sync\n'"36 ) from e37 38try:39 from ..models import FinbenchAction, FinbenchObservation40 from .FinBench_environment import FinbenchEnvironment41except ImportError:42 from FinBench.models import FinbenchAction, FinbenchObservation43 from FinBench.server.FinBench_environment import FinbenchEnvironment44 45 46app = create_app(47 FinbenchEnvironment,48 FinbenchAction,49 FinbenchObservation,50 env_name="FinBench",51 max_concurrent_envs=1,52)53 54 55def main(host: str = "0.0.0.0", port: int = 8000):56 """57 Entry point for direct execution via uv run or python -m.58 59 This function enables running the server without Docker:60 uv run --project . server61 uv run --project . server --port 800162 python -m FinBench.server.app63 64 Args:65 host: Host address to bind to (default: "0.0.0.0")66 port: Port number to listen on (default: 8000)67 68 For production deployments, consider using uvicorn directly with69 multiple workers:70 uvicorn FinBench.server.app:app --workers 471 """72 import uvicorn73 74 uvicorn.run(app, host=host, port=port)75 76 77if __name__ == "__main__":78 main()79 