第二十七轮: 三线直传(/v1/messages,/v1/responses)+删除路由别名;第二十八轮: element-plus 按需引入+死代码清理+前端支持格式列/API Key 文档
This commit is contained in:
1 parent
1b54802ad3
commit
4c1973b13d
28 files changed
+3016
-1263
No files matched your search
+63
-21
@@ -2,6 +2,9 @@
|
||||
|
||||
用法: python live_check.py --key <wjd-xxx> [--url http://127.0.0.1:8808]
|
||||
网关已开鉴权,所有端点带 Authorization: Bearer <key>。
|
||||
|
||||
第二十七轮(2026-09-18):路由别名 wjd 已整体删除 → 本脚本里的模型一律用**真实模型 id**,
|
||||
并新增「三线直传」与「跨线 400」检查(chat/completions · messages · responses 各按自家协议直传)。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -12,12 +15,25 @@ import httpx
|
||||
|
||||
PASS, FAIL, WARN = [], [], []
|
||||
|
||||
# 第二十七轮: 三线直传用到的真实模型 id
|
||||
CHAT_MODEL = "agnes-3.0-flash" # 只声明 chat/completions 线
|
||||
THREE_LINE_MODEL = "deepseek-v4.1-flash" # 实测三线全通(chat/completions · messages · responses)
|
||||
|
||||
|
||||
def check(name: str, cond: bool, detail: str = "") -> None:
|
||||
(PASS if cond else FAIL).append(name)
|
||||
print(f"[{'PASS' if cond else 'FAIL'}] {name} {detail}")
|
||||
|
||||
|
||||
def check_or_warn(name: str, cond: bool, detail: str = "") -> None:
|
||||
"""上游侧的结果不定(模型/额度/协议细节),不算硬失败 —— 但网关侧的闸门必须硬判。"""
|
||||
if cond:
|
||||
PASS.append(name)
|
||||
print(f"[PASS] {name} {detail}")
|
||||
else:
|
||||
warn(name, detail)
|
||||
|
||||
|
||||
def warn(name: str, detail: str = "") -> None:
|
||||
WARN.append(name)
|
||||
print(f"[WARN] {name} {detail}")
|
||||
@@ -37,76 +53,102 @@ def main() -> int:
|
||||
j = r.json() if r.status_code == 200 else {}
|
||||
check("GET / 根导航", r.status_code == 200 and "endpoints" in j, f"{r.status_code}")
|
||||
|
||||
# 2) 走路由别名 wjd 的真实 chat(验证 route 维度指标)
|
||||
# 2) 真实 chat(第二十七轮: 不再有路由别名 —— model 就是真实模型 id,
|
||||
# 网关不替用户挑模型,served_model 必须与请求的 id 一致)
|
||||
r = c.post(f"{base}/v1/chat/completions", json={
|
||||
"model": "wjd", "messages": [{"role": "user", "content": "回复:OK"}], "max_tokens": 12})
|
||||
"model": CHAT_MODEL, "messages": [{"role": "user", "content": "回复:OK"}], "max_tokens": 12})
|
||||
ok = r.status_code == 200 and len(r.json().get("choices", [])) > 0
|
||||
served = r.json().get("served_model") if ok else None
|
||||
check("POST chat 走路由 wjd", ok, f"{r.status_code} served={served}")
|
||||
check(f"POST chat 真实模型 {CHAT_MODEL}", ok, f"{r.status_code} served={served}")
|
||||
check("served_model == 请求的 model(不再有 fallback 换模型)", served == CHAT_MODEL,
|
||||
f"served={served}")
|
||||
|
||||
# 3) 未知模型 → 400(Bug 15)
|
||||
r = c.post(f"{base}/v1/chat/completions", json={
|
||||
"model": "__nope__", "messages": [{"role": "user", "content": "x"}]})
|
||||
check("未知模型 → 400(Bug 15)", r.status_code == 400, f"{r.status_code}")
|
||||
|
||||
# 4) /metrics 里 routes.wjd 的 ok 应 ≥1(Bug 8:route 维度不再恒 0)
|
||||
# 4) /metrics:模型维度在记账;路由维度已随路由功能删除(不该再出现)
|
||||
r = c.get(f"{base}/metrics")
|
||||
j = r.json() if r.status_code == 200 else {}
|
||||
wjd = (j.get("routes") or {}).get("wjd") or {}
|
||||
mine = (j.get("calls") or {}).get(CHAT_MODEL) or {}
|
||||
check("GET /metrics 已启用", r.status_code == 200, f"{r.status_code}")
|
||||
check("routes.wjd.ok ≥ 1(Bug 8)", wjd.get("ok", 0) >= 1, f"wjd={wjd}")
|
||||
check(f"calls.{CHAT_MODEL}.ok ≥ 1(模型维度记账)", mine.get("ok", 0) >= 1, f"{mine}")
|
||||
check("路由维度已删除(无 routes / fallback_total)",
|
||||
"routes" not in j and "fallback_total" not in j, f"keys={sorted(j)[:8]}…")
|
||||
|
||||
# 5) 流式 SSE(走 wjd)
|
||||
# 5) 流式 SSE(真实模型)
|
||||
body = ""
|
||||
with c.stream("POST", f"{base}/v1/chat/completions", json={
|
||||
"model": "wjd", "messages": [{"role": "user", "content": "数到三"}],
|
||||
"model": CHAT_MODEL, "messages": [{"role": "user", "content": "数到三"}],
|
||||
"stream": True, "max_tokens": 16}) as sr:
|
||||
if sr.status_code == 200:
|
||||
body = "".join(sr.iter_text())
|
||||
check("流式 SSE 走 wjd 且以 [DONE] 收尾", sr.status_code == 200 and "[DONE]" in body,
|
||||
check("流式 SSE 且以 [DONE] 收尾", sr.status_code == 200 and "[DONE]" in body,
|
||||
f"{sr.status_code} len={len(body)}")
|
||||
|
||||
# 6) 流式后 routes.wjd.ok 继续累加(流式也记 route)
|
||||
# 6) 流式也计入模型维度指标
|
||||
r = c.get(f"{base}/metrics")
|
||||
wjd2 = ((r.json().get("routes") or {}).get("wjd") or {}) if r.status_code == 200 else {}
|
||||
check("流式也计入 routes.wjd(Bug 8 补充)", wjd2.get("ok", 0) > wjd.get("ok", 0),
|
||||
f"before={wjd.get('ok',0)} after={wjd2.get('ok',0)}")
|
||||
mine2 = ((r.json().get("calls") or {}).get(CHAT_MODEL) or {}) if r.status_code == 200 else {}
|
||||
check("流式也计入 calls(Bug 8 补充)", mine2.get("ok", 0) > mine.get("ok", 0),
|
||||
f"before={mine.get('ok',0)} after={mine2.get('ok',0)}")
|
||||
|
||||
# 7) Prometheus 指标
|
||||
# 7) 三线直传(第二十七轮新增)
|
||||
# 7a) messages 线:Anthropic 协议原样直传
|
||||
r = c.post(f"{base}/v1/messages", json={
|
||||
"model": THREE_LINE_MODEL, "max_tokens": 16,
|
||||
"messages": [{"role": "user", "content": "回复:OK"}]})
|
||||
check_or_warn(f"POST /v1/messages 直传({THREE_LINE_MODEL})", r.status_code == 200,
|
||||
f"{r.status_code} {str(r.text)[:120]}")
|
||||
# 7b) responses 线:OpenAI Responses 协议原样直传
|
||||
r = c.post(f"{base}/v1/responses", json={
|
||||
"model": THREE_LINE_MODEL, "input": "回复:OK", "max_tokens": 16})
|
||||
check_or_warn(f"POST /v1/responses 直传({THREE_LINE_MODEL})", r.status_code == 200,
|
||||
f"{r.status_code} {str(r.text)[:120]}")
|
||||
# 7c) 跨线闸门:只支持 chat/completions 的模型打 /v1/messages → 必须 400
|
||||
# (上游对错线请求回的是 500/401 这类跟"格式选错"无关的错误,网关必须在入口挡住)
|
||||
r = c.post(f"{base}/v1/messages", json={
|
||||
"model": CHAT_MODEL, "max_tokens": 16,
|
||||
"messages": [{"role": "user", "content": "x"}]})
|
||||
detail = str(r.text)[:160]
|
||||
check(f"跨线请求 → 400({CHAT_MODEL} 不支持 messages 线)",
|
||||
r.status_code == 400 and "messages" in detail, f"{r.status_code} {detail}")
|
||||
|
||||
# 8) Prometheus 指标
|
||||
r = c.get(f"{base}/metrics/prometheus")
|
||||
check("GET /metrics/prometheus", r.status_code == 200 and "api_gateway" in r.text, f"{r.status_code}")
|
||||
|
||||
# 8) 访问日志
|
||||
# 9) 访问日志
|
||||
r = c.get(f"{base}/logs?n=5")
|
||||
check("GET /logs", r.status_code == 200 and isinstance(r.json().get("entries"), list), f"{r.status_code}")
|
||||
|
||||
# 9) provider 健康(可达性 = 2xx,Bug 11)
|
||||
# 10) provider 健康(可达性 = 2xx,Bug 11)
|
||||
r = c.get(f"{base}/health/agnes")
|
||||
j = r.json() if r.status_code == 200 else {}
|
||||
check("GET /health/agnes reachable(2xx)", r.status_code == 200 and j.get("reachable") is True,
|
||||
f"{r.status_code} reachable={j.get('reachable')} code={j.get('status_code')}")
|
||||
|
||||
# 10) 动态 CORS(Bug 6):预检 + 通配来源
|
||||
# 11) 动态 CORS(Bug 6):预检 + 通配来源
|
||||
r = c.options(f"{base}/v1/chat/completions", headers={
|
||||
"Origin": "https://demo.example", "Access-Control-Request-Method": "POST"})
|
||||
check("CORS 预检 200 且回 ACAO", r.status_code == 200 and
|
||||
r.headers.get("access-control-allow-origin") in ("*", "https://demo.example"),
|
||||
f"{r.status_code} ACAO={r.headers.get('access-control-allow-origin')}")
|
||||
|
||||
# 11) 413 体积限制
|
||||
# 12) 413 体积限制
|
||||
r = c.post(f"{base}/v1/chat/completions", content=b"x" * 3_000_000,
|
||||
headers={"Content-Type": "application/json"})
|
||||
check("超大请求体 → 413", r.status_code == 413, f"{r.status_code}")
|
||||
|
||||
# 12) batch(真实)
|
||||
# 13) batch(真实模型)
|
||||
r = c.post(f"{base}/v1/chat/completions/batch", json={
|
||||
"model": "wjd", "max_concurrency": 2,
|
||||
"model": CHAT_MODEL, "max_concurrency": 2,
|
||||
"items": [{"messages": [{"role": "user", "content": "说 hi"}], "label": "a"},
|
||||
{"messages": [{"role": "user", "content": "说 yo"}], "label": "b"}]})
|
||||
ok = r.status_code == 200 and r.json().get("count") == 2 and all(x["ok"] for x in r.json()["results"])
|
||||
check("POST batch 2 项全成功", ok, f"{r.status_code}")
|
||||
|
||||
# 13) 图像(真实,可能较慢 / 上游不支持则 WARN)
|
||||
# 14) 图像(真实,可能较慢 / 上游不支持则 WARN)
|
||||
try:
|
||||
r = c.post(f"{base}/v1/images/generations", json={
|
||||
"model": "agnes-image-2.5-flash", "prompt": "a plain red square", "size": "1K"}, timeout=120)
|
||||
|
||||
Reference in new issue
Block a user