feat: 故障推送 / 公需课自动重学 / 插件解耦,发版 v0.0.8
体检修复:启动日志不再打印 AUTH_TOKEN、密钥可清空、推送失败不占整段冷却、目录名与文案统一成 plugins/。
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""大模型连通性测试接口。"""
|
||||
import time
|
||||
|
||||
from study_tool.webapp import app
|
||||
|
||||
from study_tool.config.settings import load_settings
|
||||
from study_tool.llm import llm_chat
|
||||
from study_tool.models import LlmTestIn
|
||||
|
||||
|
||||
@app.post("/api/llm/test")
|
||||
def api_llm_test(b: LlmTestIn):
|
||||
cfg = dict(load_settings()["llm"])
|
||||
if b.base_url.strip():
|
||||
cfg["base_url"] = b.base_url.strip()
|
||||
if b.model.strip():
|
||||
cfg["model"] = b.model.strip()
|
||||
if b.api_key.strip():
|
||||
cfg["api_key"] = b.api_key.strip()
|
||||
cfg["timeout"] = max(10, min(120, int(b.timeout or 60)))
|
||||
if not cfg.get("api_key"):
|
||||
return {"ok": False, "error": "没有 api_key"}
|
||||
t0 = time.time()
|
||||
try:
|
||||
reply = llm_chat([{"role": "user", "content": "只回复两个字符:ok"}], cfg,
|
||||
max_tokens=8, json_mode=False)
|
||||
return {"ok": True, "ms": int((time.time() - t0) * 1000), "reply": (reply or "")[:80]}
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": str(e)[:300]}
|
||||
Reference in New Issue
Block a user