feat(calllog): 列表加「内容」列,显示请求体 messages 的 content
- 新增 prompt_preview():抽取用户实际输入(兼容 chat/responses/messages 三种格式) - 列表返回 prompt_text(单行/240字),不再吐原文;详情也带 prompt_text - 前端:模型列后新增「内容」列 + 详情弹窗「内容」块 - 版本 2.9.0 → 2.9.1
This commit is contained in:
1 parent
c88a72ab8e
commit
fd7f0d8d3f
6 files changed
+90
-3
No files matched your search
@@ -1,5 +1,17 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 2026-10-23 · 调用日志列表加「内容」列(2.9.0 → 2.9.1)
|
||||
|
||||
老板:「列表的模型后面加一个字段,显示请求体的 content 内容」。
|
||||
|
||||
- 新增 `prompt_preview()`:从请求体 JSON 里抽出**用户实际说的话**(不是整包 JSON)——
|
||||
兼容 OpenAI chat / responses(`messages[-1].content`、`input` 字符串或数组)与
|
||||
Anthropic messages(`content` 字符串或多段 text parts);非 JSON 时退回原文。
|
||||
- `GET /logs/calls` 现在每行都返回 `prompt_text`(单行、压空白、截 240 字),
|
||||
**列表不再吐原文 `prompt`**(几千字整包会拖慢列表);`content=1` 时仍给完整原文。
|
||||
- `GET /logs/calls/{id}` 也带 `prompt_text`,详情弹窗第一屏就能看到用户说了什么。
|
||||
- 前端:模型列后面新增「内容」列(超长省略 + 悬停看全文);详情弹窗增加「内容」块。
|
||||
|
||||
## 2026-10-23 · 指标改由数据库提供(重启不再清零)+ 月度用量导出(2.8.0 → 2.9.0)
|
||||
|
||||
老板:「全做」—— 指上一条列出的两项:① Dashboard 统计改从数据库读;② 按账号月度用量导出。
|
||||
|
||||
+64
-2
@@ -101,6 +101,60 @@ def _clip(v: Any, n: int = CONTENT_MAX) -> str:
|
||||
return s
|
||||
|
||||
|
||||
def prompt_preview(body: str | None, limit: int = 240) -> str:
|
||||
"""从请求体 JSON 里抽出「用户实际说的话」,给列表做一行预览。
|
||||
|
||||
兼容三种入站格式:
|
||||
· OpenAI chat / responses: `messages[-1].content`(字符串或多段 text parts)、`input`
|
||||
· Anthropic messages: `messages[-1].content`(同上)
|
||||
· 非 JSON / 解析失败: 退回原文前 limit 字(换行压成空格)
|
||||
"""
|
||||
if not body:
|
||||
return ""
|
||||
try:
|
||||
import json as _json
|
||||
d = _json.loads(body)
|
||||
except Exception: # noqa: BLE001
|
||||
return " ".join(str(body).split())[:limit]
|
||||
text = ""
|
||||
msgs = d.get("messages") if isinstance(d, dict) else None
|
||||
if not isinstance(msgs, list) or not msgs:
|
||||
msgs = d.get("input") if isinstance(d, dict) else None
|
||||
if isinstance(msgs, list) and msgs:
|
||||
last = msgs[-1]
|
||||
if isinstance(last, dict):
|
||||
c = last.get("content")
|
||||
if isinstance(c, str):
|
||||
text = c
|
||||
elif isinstance(c, list):
|
||||
parts = []
|
||||
for p in c:
|
||||
if isinstance(p, dict):
|
||||
t = p.get("text") or p.get("input_text") or p.get("content")
|
||||
if isinstance(t, str):
|
||||
parts.append(t)
|
||||
text = " ".join(parts)
|
||||
elif isinstance(last, str):
|
||||
text = last
|
||||
if not text and isinstance(d, dict):
|
||||
for k in ("prompt", "content", "text", "input"):
|
||||
v = d.get(k)
|
||||
if isinstance(v, str) and v:
|
||||
text = v
|
||||
break
|
||||
if isinstance(v, list) and v: # responses 线的 input 可能是消息数组
|
||||
lastv = v[-1]
|
||||
if isinstance(lastv, dict) and isinstance(lastv.get("content"), str):
|
||||
text = lastv["content"]
|
||||
break
|
||||
if isinstance(lastv, str):
|
||||
text = lastv
|
||||
break
|
||||
if not text:
|
||||
text = body
|
||||
return " ".join(str(text).split())[:limit]
|
||||
|
||||
|
||||
class CallLogStore:
|
||||
"""SQLite 调用日志存储。线程安全的单写者 + 单读连接。"""
|
||||
|
||||
@@ -282,10 +336,12 @@ class CallLogStore:
|
||||
return {"total": 0, "items": [], "enabled": False}
|
||||
where, params = self._where(start=start, end=end, account=account, model=model,
|
||||
ok=ok, status=status, kind=kind, q=q)
|
||||
# 列表页也要「内容」列(2026-10-23 老板要求):始终取 prompt 生成单行预览,
|
||||
# 但不把动辄几千字的原文整包吐给列表(with_content=1 才给完整 prompt/completion)。
|
||||
cols = ("id, ts, rid, account, key_id, kind, method, path, model, served, provider, "
|
||||
"caller, stream, ok, status, latency_ms, ip, ua, ver")
|
||||
"caller, stream, ok, status, latency_ms, ip, ua, ver, prompt")
|
||||
if with_content:
|
||||
cols += ", prompt, completion"
|
||||
cols += ", completion"
|
||||
limit = max(1, min(int(limit), 500))
|
||||
offset = max(0, int(offset))
|
||||
try:
|
||||
@@ -303,6 +359,10 @@ class CallLogStore:
|
||||
for r in rows:
|
||||
d = dict(zip(names, r))
|
||||
d["ts_iso"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(d["ts"]))
|
||||
raw_prompt = d.get("prompt") or ""
|
||||
d["prompt_text"] = prompt_preview(raw_prompt)
|
||||
if not with_content:
|
||||
d.pop("prompt", None) # 列表只给预览,不吐原文
|
||||
items.append(d)
|
||||
return {"total": total, "items": items, "limit": limit, "offset": offset}
|
||||
|
||||
@@ -320,6 +380,8 @@ class CallLogStore:
|
||||
return None
|
||||
d = dict(zip(names, row))
|
||||
d["ts_iso"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(d["ts"]))
|
||||
# 详情也带一份「提取出的 content」,弹窗里第一屏就能看到用户说了什么
|
||||
d["prompt_text"] = prompt_preview(d.get("prompt"))
|
||||
return d
|
||||
|
||||
def stats(self, days: int = 7) -> dict[str, Any]:
|
||||
|
||||
+1
-1
@@ -351,7 +351,7 @@ _docs_on = config.server.docs_enabled # 安全默认关(report: /docs、/ope
|
||||
# 2026-09-30: 2.6.1 → 2.7.0(按老板要求整个删除「火山方舟 Coding Plan」供应商:配置/模型/代码/文档/前端下拉/环境变量全清)。
|
||||
# 2026-09-30: 2.7.0 → 2.7.1(界面提示白话化:熔断器→供应商自动保护、引擎→运行环境、slug→标识;删 120 个未引用死键)。
|
||||
# ★ 版本号纪律:每次改动都要往上加,小改动加小版本号、大改动加大版本号(README 有专章)。
|
||||
VERSION = "2.9.0"
|
||||
VERSION = "2.9.1"
|
||||
|
||||
app = FastAPI(
|
||||
title="API Gateway",
|
||||
|
||||
@@ -237,6 +237,7 @@ export default {
|
||||
colFail: 'Failed',
|
||||
colFailRate: 'Fail rate',
|
||||
colModels: 'Models',
|
||||
colContent: 'Content',
|
||||
},
|
||||
|
||||
users: {
|
||||
|
||||
@@ -237,6 +237,7 @@ export default {
|
||||
colFail: '失败',
|
||||
colFailRate: '失败率',
|
||||
colModels: '模型数',
|
||||
colContent: '内容',
|
||||
},
|
||||
|
||||
users: {
|
||||
|
||||
@@ -53,6 +53,12 @@
|
||||
<span v-if="row.served && row.served !== row.model" class="sub"> → {{ row.served }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- 2026-10-23 老板要求:模型后面加「内容」——显示请求体里 messages 的 content(单行预览) -->
|
||||
<el-table-column :label="t('calllogs.colContent')" min-width="240" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span :class="{ 'muted-t': !row.prompt_text }">{{ row.prompt_text || '—' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="t('calllogs.colLatency')" width="92">
|
||||
<template #default="{ row }">{{ row.latency_ms != null ? row.latency_ms + 'ms' : '—' }}</template>
|
||||
</el-table-column>
|
||||
@@ -117,6 +123,10 @@
|
||||
<span><i>path</i>{{ detail.path || '—' }}</span>
|
||||
<span><i>ver</i>{{ detail.ver || '—' }}</span>
|
||||
</div>
|
||||
<div class="sec">
|
||||
<label>{{ t('calllogs.colContent') }}</label>
|
||||
<pre>{{ detail.prompt_text || '—' }}</pre>
|
||||
</div>
|
||||
<div class="sec">
|
||||
<label>{{ t('calllogs.prompt') }}</label>
|
||||
<pre>{{ detail.prompt || '—' }}</pre>
|
||||
@@ -282,6 +292,7 @@ onMounted(loadPage)
|
||||
.err-t { color: var(--err); font-weight: 600; font-variant-numeric: tabular-nums; }
|
||||
.pager-bar { display: flex; justify-content: flex-end; padding-top: 10px; }
|
||||
.sub { font-size: 11.5px; color: var(--muted-2); }
|
||||
.muted-t { color: var(--muted-2); }
|
||||
.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 14px; font-size: 12.5px; }
|
||||
.kv span { display: flex; gap: 6px; align-items: baseline; overflow: hidden; }
|
||||
.kv i { font-style: normal; color: var(--muted-2); min-width: 52px; }
|
||||
|
||||
Reference in new issue
Block a user