From 5ba3cc778b1ff234cb139799ff7dbb1aca1a83fa Mon Sep 17 00:00:00 2001 From: tzt <14718231+flying-travel@user.noreply.gitee.com> Date: Sun, 30 Aug 2026 21:26:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(v2):=20Web=20=E7=95=8C=E9=9D=A2=EF=BC=88?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D/=E5=8D=8F=E4=BD=9C=E8=BF=87=E7=A8=8B/?= =?UTF-8?q?=E4=BA=BA=E5=B7=A5=E6=A3=80=E9=AA=8C/=E6=8C=87=E6=A0=87?= =?UTF-8?q?=EF=BC=89+=20worker=20=E4=BC=98=E9=9B=85=E9=99=8D=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- gateway/api.py | 10 +++ gateway/static/index.html | 167 ++++++++++++++++++++++++++++++++++++++ router_system/worker.py | 23 ++++-- tests/test_gateway.py | 8 ++ 5 files changed, 202 insertions(+), 10 deletions(-) create mode 100644 gateway/static/index.html diff --git a/README.md b/README.md index 7818e35..43a10b6 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ - ✅ **人工检验队列**(`review.py`):sqlite 队列、抽样 + safety 强制入队、verdict/correction 回写 - ✅ **打包分发**(`scripts/setup_runtime.py`):llama-server + GGUF 下载(断点续传/大小校验) - ✅ **E1 token 经济学实验**(`scripts/bench_tokens.py` → `research/v2_experiments/`) -- ✅ **测试**:**228 项全绿**(含 v1 legacy 126 项 + v2 新模块) +- ✅ **Web 界面**(gateway/static/index.html,FastAPI 托管,无构建):对话 / 协作过程(交流文本可视化)/ 人工检验 / 指标 四视图 +- ✅ **测试**:**229 项全绿**(含 v1 legacy 126 项 + v2 新模块) --- @@ -66,6 +67,7 @@ C:\Python314\python.exe -m venv .venv # 4. 启动网关(v2 /chat 默认走 mock worker,无需 API key/模型即可演示) .venv\Scripts\python.exe scripts/serve.py --port 8000 +# 浏览器打开 http://127.0.0.1:8000/ 使用 Web 界面(对话 / 协作过程 / 人工检验 / 指标) # 5. 调用 curl http://127.0.0.1:8000/health diff --git a/gateway/api.py b/gateway/api.py index da12dcf..ee7510b 100644 --- a/gateway/api.py +++ b/gateway/api.py @@ -107,6 +107,9 @@ class HealthResponse(BaseModel): # ---- FastAPI 应用 ---- try: from fastapi import FastAPI, HTTPException + from fastapi.responses import HTMLResponse + + _INDEX_PATH = Path(__file__).resolve().parent / "static" / "index.html" app = FastAPI( title="端云协同 LLM 协作系统", @@ -118,6 +121,13 @@ try: async def health(): return get_router().health() + @app.get("/", response_class=HTMLResponse, tags=["ui"]) + async def index(): + """端云协同 Web 界面(单文件前端,无需构建)。""" + if _INDEX_PATH.exists(): + return HTMLResponse(_INDEX_PATH.read_text(encoding="utf-8")) + return HTMLResponse("
缺少 gateway/static/index.html
") + # ---------------- v2:/chat ---------------- @app.post("/chat", tags=["chat"]) async def chat(req: QueryRequest): diff --git a/gateway/static/index.html b/gateway/static/index.html new file mode 100644 index 0000000..33d8924 --- /dev/null +++ b/gateway/static/index.html @@ -0,0 +1,167 @@ + + + + + +