updated app.py
Browse files- server/app.py +44 -1
server/app.py
CHANGED
|
@@ -2,7 +2,7 @@ import sys
|
|
| 2 |
import os
|
| 3 |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 4 |
|
| 5 |
-
from fastapi import FastAPI, HTTPException
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from models import AgentAction
|
| 8 |
from server.environment import TradingEnvironment
|
|
@@ -55,6 +55,49 @@ def get_tasks():
|
|
| 55 |
]
|
| 56 |
}
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def main():
|
| 59 |
"""Entry point for the application"""
|
| 60 |
uvicorn.run(
|
|
|
|
| 2 |
import os
|
| 3 |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 4 |
|
| 5 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from models import AgentAction
|
| 8 |
from server.environment import TradingEnvironment
|
|
|
|
| 55 |
]
|
| 56 |
}
|
| 57 |
|
| 58 |
+
# Additional endpoints required by OpenEnv validator
|
| 59 |
+
|
| 60 |
+
@app.get("/metadata")
|
| 61 |
+
def get_metadata():
|
| 62 |
+
"""Return environment metadata"""
|
| 63 |
+
return {
|
| 64 |
+
"name": "Quant-Gym",
|
| 65 |
+
"description": "Financial analysis environment for testing AI agents on market data, news sentiment, and trading strategies",
|
| 66 |
+
"version": "1.0.0"
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@app.get("/schema")
|
| 70 |
+
def get_schema():
|
| 71 |
+
"""Return action, observation, and state schemas"""
|
| 72 |
+
from models import AgentAction, MarketObservation, EnvironmentState
|
| 73 |
+
|
| 74 |
+
return {
|
| 75 |
+
"action": AgentAction.model_json_schema(),
|
| 76 |
+
"observation": MarketObservation.model_json_schema(),
|
| 77 |
+
"state": EnvironmentState.model_json_schema()
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
@app.post("/mcp")
|
| 81 |
+
async def mcp_endpoint(request: Request):
|
| 82 |
+
"""MCP JSON-RPC endpoint"""
|
| 83 |
+
try:
|
| 84 |
+
body = await request.json()
|
| 85 |
+
return {
|
| 86 |
+
"jsonrpc": "2.0",
|
| 87 |
+
"id": body.get("id", 1),
|
| 88 |
+
"result": {
|
| 89 |
+
"endpoints": ["/health", "/reset", "/step", "/state", "/tasks", "/metadata", "/schema"]
|
| 90 |
+
}
|
| 91 |
+
}
|
| 92 |
+
except:
|
| 93 |
+
return {
|
| 94 |
+
"jsonrpc": "2.0",
|
| 95 |
+
"id": 1,
|
| 96 |
+
"result": {
|
| 97 |
+
"message": "MCP endpoint ready"
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
def main():
|
| 102 |
"""Entry point for the application"""
|
| 103 |
uvicorn.run(
|