FastAPI 默认监听 0.0.0.0:8000。接口当前无鉴权,设计用于本机或 SSH 隧道访问,不应直接暴露到公网。
基础地址:
http://localhost:8000
除视频文件外,响应均为 JSON。启动类接口当前以 HTTP 200 返回业务状态,调用方必须检查 status 字段。
curl 'http://localhost:8000/api/environments'{
"environments": {
"hopper": {
"name": "Hopper-v5",
"description": "...",
"difficulty": "..."
}
},
"active": "hopper"
}env 可取 hopper、walker2d、halfcheetah,缺省为 hopper。返回 CSV 行转换后的 JSON 数组。
curl 'http://localhost:8000/api/metrics/distributed?env=hopper'[
{
"step": 0,
"elapsed_sec": 2.1,
"total_steps": 16384.0,
"sps": 7801.9,
"episodes": 12,
"avg_return": 18.2,
"buffer_size": 16384.0,
"loss": 0.31,
"num_gpus": 1.0
}
]请求无 JSON body:
curl -X POST 'http://localhost:8000/api/training/distributed/start?env=hopper'成功:
{"status": "started"}重复启动:
{"status": "already running"}立即崩溃:
{
"status": "error",
"returncode": 1,
"error_detail": "Traceback ..."
}省略 env 会停止当前服务进程管理的全部训练。
curl -X POST 'http://localhost:8000/api/training/stop?env=hopper'{"status": "stopped", "environments": ["hopper"]}{"env": "hopper", "running": true}不传 env:
{"statuses": {"hopper": true, "walker2d": false, "halfcheetah": false}}返回内存中的最近训练输出。lines 缺省为 50。
{"env": "hopper", "lines": ["[Main] ..."], "total": 120}扫描 config/scaling/*.yaml:
{
"configs": {
"hopper_gpu4": {
"env": "hopper",
"num_gpus": 4,
"config_path": "config/scaling/hopper_gpu4.yaml",
"metrics_path": "output/scaling/hopper_gpu4/metrics.csv"
}
}
}curl -X POST 'http://localhost:8000/api/scaling/start?config_name=hopper_gpu4'{
"status": "started",
"config": {"env": "hopper", "num_gpus": 4, "config_path": "..."}
}{"statuses": {"hopper_gpu4": true}}{
"gpu_count": 1,
"gpus": [{"index": 0, "name": "NVIDIA ...", "memory_gb": 24.0}],
"ray_resources": {}
}异步生成单机与分布式策略视频。
返回 idle、generating、completed 或 error 状态及错误信息。
成功时返回 MP4 文件;文件不存在时返回 JSON:
{"error": "Video not found"}连接:
ws://localhost:8000/ws/training
服务端每秒推送当前活跃环境的指标:
{
"type": "metrics",
"env": "hopper",
"distributed": [],
"single": []
}训练退出时推送:
{
"type": "training_stopped",
"env": "hopper",
"returncode": 1,
"error_detail": "可选错误详情"
}