direct-backend-test.py 1.26 KB
"""验直连后端端口这条老路还通不通——调度层是加在旁边的,不该动到它。

走的是 API.md 里那段完整调用示例的形状:POST 拿 id → 轮询 → 下载。
"""
import json, time, urllib.request

API = "http://127.0.0.1:8010"
SPEC = {"prompt": "一只橘猫趴在洒满阳光的窗台上,慢慢眨眼", "frames": 22, "steps": 4,
        "turbo": True, "seed": 99}


def call(path, data=None, timeout=60):
    req = urllib.request.Request(API + path, data=data,
                                 headers={"Content-Type": "application/json"} if data else {})
    with urllib.request.urlopen(req, timeout=timeout) as r:
        return json.load(r)


print("health:", call("/health"))
job = call("/v1/videos", json.dumps(SPEC).encode())
print("提交:", job)

while True:
    time.sleep(20)
    j = call(f"/v1/videos/{job['id']}")
    print(" ", j["status"], j.get("elapsed_seconds", 0), "s", flush=True)
    if j["status"] in ("done", "failed"):
        break

if j["status"] == "failed":
    raise SystemExit("失败: " + j["error"])

with urllib.request.urlopen(f"{API}/v1/videos/{job['id']}/file", timeout=300) as r:
    data = r.read()
print(f"下载 {len(data)} 字节,后端记录 {j['size_bytes']},一致={len(data) == j['size_bytes']}")