From 0f55483eafbc7ffe29cb39f4ffc689435611d4c1 Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Wed, 2 Sep 2026 13:38:13 +0800 Subject: [PATCH] =?UTF-8?q?v2.4.1=20=E8=AF=84=E6=B5=8B=E7=AB=99=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=B8=A6=E7=A1=AC=E4=BB=B6=EF=BC=9A=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20/api/gpu=20=E8=87=AA=E5=8A=A8=E6=8E=A2=E6=B5=8B=E6=9C=AC?= =?UTF-8?q?=E6=9C=BAGPU=EF=BC=8C=E8=AF=84=E6=B5=8B=E7=AB=99=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=8D=A1=E7=89=87=E5=8A=A0=E7=A1=AC=E4=BB=B6/GPU?= =?UTF-8?q?=E5=AD=97=E6=AE=B5(=F0=9F=94=8D=E6=8E=A2=E6=B5=8B=E5=8F=AF?= =?UTF-8?q?=E6=94=B9)=EF=BC=8C=E5=8F=91=E9=80=81=E5=88=B0=E8=AF=84?= =?UTF-8?q?=E6=B5=8B=E7=AB=99=E6=97=B6=E9=9A=8F=E7=BB=93=E6=9E=9C=E4=B8=80?= =?UTF-8?q?=E5=B9=B6=E6=8F=90=E4=BA=A4=E7=A1=AC=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 14 ++++++++++++++ static/index.html | 7 +++++++ static/js/app.js | 26 +++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 6c2d94b..182fb19 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ """LLM 速度测试台 - Flask 主应用""" import io import json +import subprocess import requests from flask import Flask, jsonify, request, send_file, send_from_directory @@ -24,6 +25,19 @@ def index(): return send_from_directory(app.static_folder, "index.html") +@app.route("/api/gpu") +def gpu_info(): + """自动探测本机 GPU(nvidia-smi),供评测站同步时标注硬件""" + try: + out = subprocess.check_output( + ["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"], + text=True, timeout=5, stderr=subprocess.DEVNULL) + gpus = [g.strip() for g in out.strip().splitlines() if g.strip()] + return jsonify({"ok": True, "gpus": gpus, "label": " / ".join(gpus)}) + except Exception as e: + return jsonify({"ok": True, "gpus": [], "label": "", "error": str(e)}) + + @app.route("/api/health") def health(): running = [tid for tid, r in RUNNERS.items() if r.is_alive()] diff --git a/static/index.html b/static/index.html index 158e229..db3e591 100644 --- a/static/index.html +++ b/static/index.html @@ -126,6 +126,13 @@
👥
+
+ +
+
🖥
+ +
+
测试完成后,在历史列表或详情里点「📤 发送到评测站」,一键把结果发布到模型评测网站(端口 16066)对应账号下。
diff --git a/static/js/app.js b/static/js/app.js index 6a589d7..05ac47c 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -833,19 +833,41 @@ function evalSettings() { return { url: (localStorage.getItem("evalUrl") || "http://127.0.0.1:16066").replace(/\/+$/, ""), account: localStorage.getItem("evalAccount") || "默认账号", + hardware: localStorage.getItem("evalHardware") || "", }; } function loadEvalSettings() { const s = evalSettings(); - const u = $("#eval-url"), a = $("#eval-account"); + const u = $("#eval-url"), a = $("#eval-account"), h = $("#eval-hardware"); if (u) u.value = s.url; if (a) a.value = s.account; + if (h) h.value = s.hardware; } function saveEvalSettings() { localStorage.setItem("evalUrl", $("#eval-url").value.trim() || "http://127.0.0.1:16066"); localStorage.setItem("evalAccount", $("#eval-account").value.trim() || "默认账号"); + localStorage.setItem("evalHardware", $("#eval-hardware").value.trim() || ""); +} + +async function detectGpu() { + const box = $("#eval-result"); + try { + const r = await api("/api/gpu"); + if (r.label) { + $("#eval-hardware").value = r.label; + saveEvalSettings(); + box.hidden = false; box.className = "conn-result ok"; + box.textContent = `✅ 已探测到 GPU:${r.label}`; + } else { + box.hidden = false; box.className = "conn-result fail"; + box.textContent = "未探测到 GPU(nvidia-smi 不可用),可手动填写硬件描述"; + } + } catch (e) { + box.hidden = false; box.className = "conn-result fail"; + box.textContent = "❌ 探测失败:" + e.message; + } } async function testEvalConn() { @@ -888,6 +910,7 @@ async function sendToEval(id) { source_site: "llm-speed-tester", provider: t.provider || "", model: t.model || "", + hardware: s.hardware, test_name: t.name || "", summary: t.summary || {}, gen: t.gen || {}, @@ -951,6 +974,7 @@ function bind() { $("#btn-test-conn").addEventListener("click", testConnection); $("#btn-eval-test").addEventListener("click", testEvalConn); + $("#btn-detect-gpu").addEventListener("click", detectGpu); $("#btn-start").addEventListener("click", startTest); $("#btn-cancel").addEventListener("click", stopTest); $("#btn-context-add").addEventListener("click", addContextLength);