From bb4c9281f732836d8e96f9c9d2b2731c9b7fa9a0 Mon Sep 17 00:00:00 2001 From: jidekin <294297426@qq.com> Date: Fri, 23 Oct 2026 11:24:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(calllog):=20=E7=BF=BB=E8=AF=91=E9=94=AE?= =?UTF-8?q?=E7=A7=BB=E5=9B=9E=E9=A1=B6=E5=B1=82=20+=20=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=8A=E9=99=90=202000=E2=86=928000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - calllogs.* 的 i18n 段此前被插进 upload 段内部,导致新面板全部显示原始键名; 已移到 logs 之后作为顶层键,zh/en 结构复核一致 - 请求体摘要 raw[:2000]→8000、回复文本 _logsafe(...,2000)→8000(5 处), 实测 6000 字提示词可完整落库 --- CHANGELOG.md | 7 +++++ app/main.py | 12 ++++---- frontend/src/locales/en.ts | 59 +++++++++++++++++++------------------- frontend/src/locales/zh.ts | 59 +++++++++++++++++++------------------- 4 files changed, 71 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e414362..71fb5b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,13 @@ - 新组件 `CallLogs.vue`:日期范围、账号、模型、仅成功/仅失败、关键词(内容/rid/IP/UA)筛选; 列表显示时间/账号/模型/耗时/状态/流式/UA;点击行弹出详情看**完整提示词与回复**;CSV 导出。 +### 2026-10-23 补丁:翻译键位置 + 内容上限 +- **修**:`calllogs.*` 的 i18n 段首次插入时被放进了 `upload` 段内部(嵌套层级错), + 导致新面板全部显示原始键名(`calllogs.title` 之类)。已移为**顶层键**(`logs` 之后), + 并复核 zh/en 两份文件的顶层键数量与层级一致。 +- **提上限**:请求体摘要 `raw[:2000]` → `8000`,回复文本 `_logsafe(..., 2000)` → `8000`(5 处)。 + 实测 6000 字的提示词已能完整落库(此前会被截在 2000)。 + ### 现状说明 - `/metrics` 仍是内存态(重启清零),本次没动它;**调用日志是持久化的**, 需要历史统计时可以基于 `api_calls` 做(二期可把 Dashboard 数据源切过来)。 diff --git a/app/main.py b/app/main.py index 6c573fa..0ae0e09 100644 --- a/app/main.py +++ b/app/main.py @@ -498,7 +498,7 @@ async def in_flight_tracker(request: Request, call_next): if rid: try: raw = await request.body() - BODY_BY_RID[rid] = raw[:2000].decode("utf-8", "replace") + BODY_BY_RID[rid] = raw[:8000].decode("utf-8", "replace") if len(BODY_BY_RID) > 2 * _BODY_MAX: BODY_BY_RID.clear() except Exception: @@ -1639,7 +1639,7 @@ async def _passthrough(request: Request, protocol: str): "model": model_in, "served": model_in, "provider": pkey, "caller": caller, "ok": ok, "stream": False, "response": _logsafe(_resp_text(data) if ok else _upstream_detail( - json.dumps(data, ensure_ascii=False) if isinstance(data, dict) else str(data)), 2000)}) + json.dumps(data, ensure_ascii=False) if isinstance(data, dict) else str(data)), 8000)}) if not ok: # 直传口径:上游的错误体**原样**回给客户端(错误文案也不翻译),只加一个 @@ -1684,7 +1684,7 @@ async def _passthrough_stream(request, rid, caller, protocol, adapter, cb, _access.add({"method": "POST", "kind": "chat", "path": f"/v1/{protocol}", "rid": rid, "model": model_in, "served": model_in, "provider": pkey, "caller": caller, "ok": False, "stream": True, - "response": _logsafe(_upstream_detail(raw.decode("utf-8", "replace")), 2000)}) + "response": _logsafe(_upstream_detail(raw.decode("utf-8", "replace")), 8000)}) return Response(content=raw, status_code=resp.status_code, media_type=ctype, headers=headers) scanner = _UsageScanner(protocol) @@ -2039,7 +2039,7 @@ async def _chat_once(cfg, rid, caller, request, req, model_id, messages, tools): _access.add({"method": "POST", "kind": "chat", "path": "/v1/chat/completions", "rid": rid, "model": req.model, "served": model_id, "provider": pkey, "caller": caller, "ok": True, "stream": False, - "response": _logsafe(_resp_text(result), 2000)}) + "response": _logsafe(_resp_text(result), 8000)}) resp = { "id": result.get("id", "") or f"chatcmpl-{rid}", "object": "chat.completion", "created": int(time.time()), "model": req.model, @@ -2167,7 +2167,7 @@ def _stream_response(request, req, model_id, messages, tools): _access.add({"method": "POST", "kind": "chat", "path": "/v1/chat/completions", "rid": rid, "model": req.model, "served": model_id, "provider": pkey, "caller": caller, "ok": True, "stream": True, - "response": _logsafe(_stream_log_text(resp_parts, reason_parts), 2000)}) + "response": _logsafe(_stream_log_text(resp_parts, reason_parts), 8000)}) # 功能 8: 流式末尾发一个 usage 块(累计自上游 chunks 的 usage,若有) if stream_usage: uf = {'id': f'chatcmpl-{rid}', 'object': 'chat.completion.chunk', 'created': int(time.time()), @@ -2185,7 +2185,7 @@ def _stream_response(request, req, model_id, messages, tools): _access.add({"method": "POST", "kind": "chat", "path": "/v1/chat/completions", "rid": rid, "model": req.model, "served": model_id, "provider": pkey, "caller": caller, "ok": False, "stream": True, "error": str(e)[:200], - "response": _logsafe(_stream_log_text(resp_parts, reason_parts), 2000)}) + "response": _logsafe(_stream_log_text(resp_parts, reason_parts), 8000)}) # 第六轮: 已向客户端输出过 content 时本来就无法回退(第二十七轮起更没有下一个 # 模型可退),统一发错误帧 + [DONE] 收尾,避免破坏已输出的 SSE 流。 yield f"data: {json.dumps({'error': str(e), 'served_model': model_id}, ensure_ascii=False)}\n\n" diff --git a/frontend/src/locales/en.ts b/frontend/src/locales/en.ts index 1642335..ead80b2 100644 --- a/frontend/src/locales/en.ts +++ b/frontend/src/locales/en.ts @@ -203,6 +203,34 @@ export default { streaming: 'Streaming', loadErr: 'Failed to load logs', }, + calllogs: { + title: 'Call log (persisted)', + count: '{n} rows', + failN: '{n} failed', + avgMs: 'avg {n}ms', + startDate: 'Start', + endDate: 'End', + account: 'Account', + model: 'Model', + result: 'Result', + onlyOk: 'OK only', + onlyFail: 'Failed only', + keyword: 'Keyword (content/rid/IP/UA)', + colTime: 'Time', + colAccount: 'Account', + colModel: 'Model', + colLatency: 'Latency', + colStatus: 'Status', + colStream: 'Stream', + colUa: 'UA', + yes: 'yes', + no: 'no', + detailTitle: 'Call detail', + prompt: 'Prompt (request body, truncated)', + completion: 'Completion (truncated)', + loading: 'Loading…', + }, + users: { viewLogs: 'View logs', viewActivity: 'Activity', @@ -819,34 +847,5 @@ export default { errNotAudio: '{name} is not an audio file (supported: {ext})', errAudioTooBig: '{name} is {size}, over the reference-audio limit of {max} (please trim or compress it)', errBodyBudget: 'This request body is about {size}, over the gateway upload limit (~{max}).', - errBodyBudgetTip: 'Please use fewer materials, or smaller images/audio files.', - calllogs: { - title: 'Call log (persisted)', - count: '{n} rows', - failN: '{n} failed', - avgMs: 'avg {n}ms', - startDate: 'Start', - endDate: 'End', - account: 'Account', - model: 'Model', - result: 'Result', - onlyOk: 'OK only', - onlyFail: 'Failed only', - keyword: 'Keyword (content/rid/IP/UA)', - colTime: 'Time', - colAccount: 'Account', - colModel: 'Model', - colLatency: 'Latency', - colStatus: 'Status', - colStream: 'Stream', - colUa: 'UA', - yes: 'yes', - no: 'no', - detailTitle: 'Call detail', - prompt: 'Prompt (request body, truncated)', - completion: 'Completion (truncated)', - loading: 'Loading…', - }, - - }, + errBodyBudgetTip: 'Please use fewer materials, or smaller images/audio files.', }, } diff --git a/frontend/src/locales/zh.ts b/frontend/src/locales/zh.ts index e7ba697..c32ea8b 100644 --- a/frontend/src/locales/zh.ts +++ b/frontend/src/locales/zh.ts @@ -203,6 +203,34 @@ export default { streaming: '流式', loadErr: '加载日志失败', }, + calllogs: { + title: '调用日志(持久化)', + count: '共 {n} 条', + failN: '失败 {n}', + avgMs: '平均 {n}ms', + startDate: '开始日期', + endDate: '结束日期', + account: '账号', + model: '模型', + result: '结果', + onlyOk: '仅成功', + onlyFail: '仅失败', + keyword: '关键词(内容/rid/IP/UA)', + colTime: '时间', + colAccount: '账号', + colModel: '模型', + colLatency: '耗时', + colStatus: '状态', + colStream: '流式', + colUa: 'UA', + yes: '是', + no: '否', + detailTitle: '调用详情', + prompt: '提示词(请求体,截断记录)', + completion: '回复(截断记录)', + loading: '加载中…', + }, + users: { viewLogs: '查看日志', viewActivity: '查看活动', @@ -818,34 +846,5 @@ export default { errNotAudio: '{name} 不是音频文件(支持 {ext})', errAudioTooBig: '{name} 有 {size},超过参考音频上限 {max}(请裁剪或压缩后再传)', errBodyBudget: '本次请求体约 {size},超过网关上送上限(约 {max})。', - errBodyBudgetTip: '请减少素材数量,或换体积更小的图片/音频。', - calllogs: { - title: '调用日志(持久化)', - count: '共 {n} 条', - failN: '失败 {n}', - avgMs: '平均 {n}ms', - startDate: '开始日期', - endDate: '结束日期', - account: '账号', - model: '模型', - result: '结果', - onlyOk: '仅成功', - onlyFail: '仅失败', - keyword: '关键词(内容/rid/IP/UA)', - colTime: '时间', - colAccount: '账号', - colModel: '模型', - colLatency: '耗时', - colStatus: '状态', - colStream: '流式', - colUa: 'UA', - yes: '是', - no: '否', - detailTitle: '调用详情', - prompt: '提示词(请求体,截断记录)', - completion: '回复(截断记录)', - loading: '加载中…', - }, - - }, + errBodyBudgetTip: '请减少素材数量,或换体积更小的图片/音频。', }, }