Janesh's picture
Upload folder using huggingface_hub
16d0c12 verified
Raw
History Blame Contribute Delete
1.82 kB
"""
FastAPI application for the Email Triage OpenEnv Environment.
Uses openenv.core.env_server.http_server.create_app() to expose the
EmailTriageEnvironment over HTTP and WebSocket endpoints.
Endpoints (provided by create_app):
- POST /reset: Reset the environment
- POST /step: Execute an action
- GET /state: Get current environment state
- GET /schema: Get action/observation schemas
- GET /health: Health check
- GET /metadata: Environment metadata
- WS /ws: WebSocket endpoint for persistent sessions
Usage:
# Development:
uvicorn server.app:app --reload --host 0.0.0.0 --port 7860
# Production:
uvicorn server.app:app --host 0.0.0.0 --port 7860
# Direct execution:
python -m server.app
"""
from openenv.core.env_server.http_server import create_app
try:
from src.models import EmailTriageAction, EmailTriageObservation
from server.email_triage_environment import EmailTriageEnvironment
except ModuleNotFoundError:
from src.models import EmailTriageAction, EmailTriageObservation
from email_triage_environment import EmailTriageEnvironment
# Create the app using the OpenEnv SDK helper — this registers all standard
# endpoints (/reset, /step, /state, /schema, /health, /metadata, /mcp, /ws).
app = create_app(
EmailTriageEnvironment,
EmailTriageAction,
EmailTriageObservation,
env_name="email-triage-env",
max_concurrent_envs=1,
)
def main(host: str = "0.0.0.0", port: int = 7860) -> None:
"""Entry point for direct execution via ``uv run server`` or ``python -m server.app``.
Args:
host: Host address to bind to.
port: Port number to listen on (7860 for HF Spaces compatibility).
"""
import uvicorn
uvicorn.run(app, host=host, port=port)
if __name__ == "__main__":
main()