From 67776334a5da7dce66f7c4849eabfed47620501a Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 15 Sep 2026 16:24:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(llm/audit):=20=E6=99=BA=E8=83=BD=20excerpt?= =?UTF-8?q?=20=E2=80=94=E2=80=94=20=E9=95=BF=E8=AF=B7=E6=B1=82=E4=BD=93?= =?UTF-8?q?=E4=BC=98=E5=85=88=E6=91=98=20user=20content=20(1.0.27)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原 100 字节截前 N 字节的方式在大 body 上**全是噪声**: - 165 KB / 238 KB 请求体(带 context_management / tools 数组 / 多轮 history), 前 100 字节几乎全是 `{"context_management":{"edits":[...]}` 这种元数据 - 真正想问的 user content 完全看不到 - 之前 100 KB+ 请求复盘只能看出「这请求很大」「用了哪个模型」,看不出 「用户问了啥」 **1.0.27 智能摘录**(按 body_bytes 长度分支): - ≤ `AUDIT_EXCERPT_BYTES` (100B):保留原文(含 model + messages 完整结构, 短 query 一眼能看出完整对话) - > 100B:解析 JSON → 提取 `model` + 最后一个 role=user 的 message 的 `content`, 按 `AUDIT_CONTENT_CHARS` (200 字) 截前 N 个字符 → 输出 `{"model":"...","content":""}` - 兼容 OpenAI(content 字符串)与 Anthropic(content 是 `[{type,text}]` 数组) - 大 body 解析只读前 `AUDIT_JSON_PARSE_BYTES` (16KB),不把 165 KB 全读进内存 **保留字段不变**:body_bytes / body_hash 仍记录全文长度 + SHA256 前 16 hex; excerpt 仍是 meta.jsonl 单行;不存 body 副本。 附带:管理台「小时级趋势」直接读取 meta.jsonl 的端点 `GET /api/admin/audit/days` + `GET /api/admin/audit/day?day=YYYY-MM-DD` (admin 鉴权,剔除 excerpt / body_hash 省流量)。前端按 `ts / 3600` 自己聚合。 回归 232/0 全绿(§13 改造为智能摘录断言,新增 4 条原文/摘要/脱敏相关)。 --- rust/crates/plugin-llm/src/api.rs | 27 +++++ rust/crates/plugin-llm/src/config.rs | 22 +++- rust/crates/plugin-llm/src/llm_audit.rs | 142 ++++++++++++++++++++++-- tests/llm/e2e.sh | 81 ++++++++++---- 4 files changed, 237 insertions(+), 35 deletions(-) diff --git a/rust/crates/plugin-llm/src/api.rs b/rust/crates/plugin-llm/src/api.rs index fb5c994..2a42764 100644 --- a/rust/crates/plugin-llm/src/api.rs +++ b/rust/crates/plugin-llm/src/api.rs @@ -15,6 +15,7 @@ use ipass_core::api::{Actor, Guard, run_guarded, user_or_401}; use ipass_core::{http, util}; use crate::llm; +use crate::llm_audit; use crate::stats; use crate::stats_persist; use crate::upstreams; @@ -36,6 +37,8 @@ fn route(method: &str, uri: &str) -> Option<(Guard, Handler)> { ("GET", "/api/admin/usage") => (Guard::Admin, h_admin_usage), ("GET", "/api/admin/stats/persist") => (Guard::Admin, h_admin_stats_persist), ("POST", "/api/admin/stats/dump") => (Guard::Admin, h_admin_stats_dump), + ("GET", "/api/admin/audit/days") => (Guard::Admin, h_admin_audit_days), + ("GET", "/api/admin/audit/day") => (Guard::Admin, h_admin_audit_day), ("GET", "/api/v1/models") => (Guard::User, h_my_models), ("GET", "/api/v1/usage") => (Guard::User, h_my_usage), ("GET", "/api/v1/upstreams") => (Guard::User, h_my_upstreams), @@ -399,3 +402,27 @@ fn h_admin_stats_dump(r: *mut ngx_http_request_t, _actor: Actor) -> Status { Err(e) => http::fail(r, HTTPStatus::INTERNAL_SERVER_ERROR, &e), } } + +/// 列出审计目录所有有 `meta.jsonl` 的日期(按新→旧排序) +fn h_admin_audit_days(r: *mut ngx_http_request_t, _actor: Actor) -> Status { + let days = llm_audit::list_days(); + http::ok(r, json!({ "days": days, "count": days.len() }), "ok") +} + +/// 读某天 meta.jsonl 的所有行(剔除 excerpt / body_hash,**仅供管理台聚合**)。 +/// +/// 1.0.27 起管理台「小时级趋势」直接读这个端点 → 前端按 `ts / 3600` 分组聚合。 +/// 不在网关做 hour-bucket 持久化:避免给热路径加写、避免新增 shm 键空间。 +fn h_admin_audit_day(r: *mut ngx_http_request_t, _actor: Actor) -> Status { + let day = match http::params(r).get("day") { + Some(d) => d.trim().to_owned(), + None => return http::fail(r, HTTPStatus::BAD_REQUEST, "缺少 day 参数(YYYY-MM-DD)"), + }; + match llm_audit::read_day(&day) { + Ok(rows) => { + let n = rows.len(); + http::ok(r, json!({ "day": day, "rows": rows, "count": n }), "ok") + } + Err(e) => http::fail(r, HTTPStatus::BAD_REQUEST, &e), + } +} diff --git a/rust/crates/plugin-llm/src/config.rs b/rust/crates/plugin-llm/src/config.rs index 1f3b101..dac7c3b 100644 --- a/rust/crates/plugin-llm/src/config.rs +++ b/rust/crates/plugin-llm/src/config.rs @@ -160,12 +160,24 @@ pub const AUDIT_DIR_NAME: &str = "audit"; pub const AUDIT_MAX_BYTES: u64 = 1024 * 1024 * 1024; /// 容量巡检最小间隔(秒):巡检要扫整个审计树,节流避免高频 IO pub const AUDIT_PURGE_MIN_INTERVAL: i64 = 60; -/// 请求体摘录字节数(meta 同一行的 `excerpt` 字段):取 body 前 N 字节的 JSON 安全字符串。 -/// 100 字符覆盖:模型名 + 首条消息 role + 首句用户内容(短 query 整条保留)。 -/// 大 body(带 tools / 多轮 history)只看得到头,看不到尾 —— 这是设计取舍: -/// 复盘 90% 场景「当时用户问了啥 + 用了哪个模型」足够;想看全文就别存 audit, -/// 走 hot path 日志或实时抓包。 +/// 请求体摘录字节数(meta 同一行的 `excerpt` 字段): +/// **1.0.27 起改为智能摘录**——短请求体(≤ `AUDIT_EXCERPT_BYTES`)保留原文; +/// 长请求体(> `AUDIT_EXCERPT_BYTES`)解析 JSON 后提取 `model` + +/// 最后一个 user message 的 `content`(按 `AUDIT_CONTENT_CHARS` 截前 N 字符), +/// 输出 `{"model":"…","content":"…"}`。 +/// +/// 设计取舍:大 body(带 tools / 多轮 history / context_management)只看 +/// 前 100 字节 = 几乎全是结构噪声,看不到用户实际问啥。智能摘录**跳过 +/// context_management / tools / temperature** 等结构字段,**优先把 +/// 位置留给 user content**——对 100 KB+ 大请求也能复盘「当时问了啥」。 +/// +/// 想看全文就别存 audit,走 hot path 日志或实时抓包。 pub const AUDIT_EXCERPT_BYTES: usize = 100; +/// 智能 excerpt 中 user content 字符上限(按 Unicode scalar value 算)。 +/// 200 字 ≈ 100 token,够支撑「用户问了啥」的诊断;超长 prompt 截前 200 字。 +pub const AUDIT_CONTENT_CHARS: usize = 200; +/// 长请求体解析 JSON 时最多读前 N 字节。165 KB 那种大 body 不会全读进内存。 +pub const AUDIT_JSON_PARSE_BYTES: usize = 16 * 1024; /// `body_hash` 字段截断字节数(hex):完整 SHA256 64 字符太长,复盘只需要够用即可; /// 16 hex = 64 bit 抗碰撞,远超 audit「识别同一请求」的需求。 /// ⚠️ 哈希对象是**请求体全文**(流式喂入,不整份读进内存),不是 excerpt —— 只哈希 diff --git a/rust/crates/plugin-llm/src/llm_audit.rs b/rust/crates/plugin-llm/src/llm_audit.rs index 885df16..8632098 100644 --- a/rust/crates/plugin-llm/src/llm_audit.rs +++ b/rust/crates/plugin-llm/src/llm_audit.rs @@ -28,7 +28,7 @@ use std::sync::Mutex; use std::sync::atomic::{AtomicBool, AtomicI64, Ordering}; use ngx::ffi::ngx_http_request_t; -use serde_json::json; +use serde_json::{Value, json}; use crate::config; use ipass_core::store; @@ -82,10 +82,77 @@ pub fn startup() { /// (1.0.18 第一版踩过:落盘成 `"excerpt":"\"{\\\"model\\\"...\""`,读出来多一层 /// 引号,任何按前缀匹配的消费方都解析不到)。 /// -/// 截断是按**字节**做的,可能切在多字节字符中间;`from_utf8_lossy` 会把残缺尾巴 -/// 换成 U+FFFD(合法 JSON 字符),绝不产出非法 UTF-8 让序列化失败。 -fn excerpt_text(bytes: &[u8]) -> String { - String::from_utf8_lossy(bytes).into_owned() +/// 把「body 前 N 字节」解成字符串,供 meta 行的 `excerpt` 字段使用。 +/// +/// **1.0.27 起改为智能摘录**: +/// - body 长度 ≤ `AUDIT_EXCERPT_BYTES` → 保留原文(短 query 整条有诊断价值); +/// - body 长度 > `AUDIT_EXCERPT_BYTES` → 解析 JSON,提取 `model` + 最后一个 user +/// message 的 `content`(按 `AUDIT_CONTENT_CHARS` 截前 N 字),跳过 +/// `context_management` / `tools` / `temperature` 等结构噪声,输出 +/// `{"model":"…","content":"…"}`。 +/// +/// 大 body(165 KB / 238 KB 那种)原 100 字节截到的全是 `context_management` +/// 元数据 —— 智能摘录**优先把位置留给 user content**,让 audit 真有复盘价值。 +fn excerpt_text(body_bytes_total: u64, raw: &[u8]) -> String { + if body_bytes_total <= config::AUDIT_EXCERPT_BYTES as u64 { + // 短请求体:原文保留(含 model + messages 结构)。`from_utf8_lossy` 把 + // 切在多字节字符中间的残缺尾巴换成 U+FFFD,序列化器吃得下。 + return String::from_utf8_lossy(raw).into_owned(); + } + + // 长请求体:仅解析前 N 字节(受 `AUDIT_JSON_PARSE_BYTES` 限制,避免 165 KB + // 大 body 全读进内存)。 + let parse_cap = raw.len().min(config::AUDIT_JSON_PARSE_BYTES); + let v: Value = match serde_json::from_slice(&raw[..parse_cap]) { + Ok(v) => v, + Err(_) => return String::new(), // 非 JSON body(罕见,如多模态二进制)→ 空 excerpt + }; + + let model = v + .get("model") + .and_then(|m| m.as_str()) + .unwrap_or(""); + let user_content = extract_user_content(&v); + if user_content.is_empty() { + // 没找到 messages / content(异常 body)→ 空 excerpt + return String::new(); + } + // 截前 N 字(按 char 而非 byte,避免切断 UTF-8 多字节字符) + let content: String = user_content.chars().take(config::AUDIT_CONTENT_CHARS).collect(); + json!({ "model": model, "content": content }).to_string() +} + +/// 提取最后一个 user message 的 content 文本。 +/// +/// 兼容 OpenAI(`messages[-1].content` 是字符串)与 Anthropic +///(`messages[-1].content` 是 `[{type:"text", text:"..."}, ...]` 数组)。 +fn extract_user_content(v: &Value) -> String { + let messages = match v.get("messages").and_then(|m| m.as_array()) { + Some(arr) => arr, + None => return String::new(), + }; + // 倒序找最后一个 role=user 的消息(避免工具结果 assistant 回复被误算) + for m in messages.iter().rev() { + let role_ok = m.get("role").and_then(|r| r.as_str()) == Some("user"); + if !role_ok { + continue; + } + if let Some(content) = m.get("content") { + // OpenAI: content 是字符串 + if let Some(s) = content.as_str() { + return s.to_owned(); + } + // Anthropic: content 是 [{type:"text", text:"..."}, ...] 数组 + if let Some(arr) = content.as_array() { + for item in arr { + if let Some(text) = item.get("text").and_then(|t| t.as_str()) { + return text.to_owned(); + } + } + } + } + } + String::new() } /// 单遍扫描 body 临时文件:**只把前 N 字节留在内存**,其余边读边喂哈希后丢弃。 @@ -154,10 +221,11 @@ pub unsafe fn capture(r: *mut ngx_http_request_t, username: &str, slot: &str, ti return; } - // 单遍扫描:取前 N 字节作为 excerpt,全文算 SHA256(前 16 hex)。body 可能几 MB, + // 单遍扫描:取前 N 字节作为 excerpt 原文,全文算 SHA256(前 16 hex)。body 可能几 MB, // 但只有前 N 字节留在内存,且**不再复制完整文件、不再写 `<毫秒>_.json` 子文件**。 - let (prefix, full_hash, body_bytes) = scan_body(&src, config::AUDIT_EXCERPT_BYTES); - let excerpt = excerpt_text(&prefix); + let (prefix, full_hash, body_bytes) = scan_body(&src, config::AUDIT_JSON_PARSE_BYTES); + // 1.0.27 智能摘录:短请求保留原文;长请求解析 JSON → 提取 model + user content + let excerpt = excerpt_text(body_bytes, &prefix); let hash_hex = &full_hash[..config::AUDIT_HASH_HEX_BYTES.min(full_hash.len())]; let status = (*r).headers_out.status as u64; @@ -253,3 +321,61 @@ fn purge_once() -> Result<(), String> { } Ok(()) } + +// =========================================================================== +// 按日查询 helper(1.0.27):管理台「小时级趋势」直接读 meta.jsonl 不聚合 +// =========================================================================== + +/// 列出审计根下所有有 `meta.jsonl` 的日期(字典序 = 时间序)。 +/// +/// 仅返回目录名符合 `YYYY-MM-DD` 形式(防止「meta 临时文件」等噪声目录干扰)。 +pub fn list_days() -> Vec { + let Ok(rd) = fs::read_dir(root()) else { return Vec::new() }; + let mut out: Vec = rd + .flatten() + .filter_map(|e| { + let name = e.file_name().to_string_lossy().to_string(); + // 8 位 `YYYY-MM-DD` 校验 + 目录里必须有 meta.jsonl + if name.len() == 10 + && name.as_bytes()[4] == b'-' + && name.as_bytes()[7] == b'-' + && e.path().join("meta.jsonl").is_file() + { + Some(name) + } else { + None + } + }) + .collect(); + out.sort_by(|a, b| b.cmp(a)); // 倒序:最近日期在前 + out +} + +/// 读某天的 meta.jsonl,每行解析为 JSON。 +/// +/// **剔除 excerpt / body_hash** —— excerpt 含请求体前 100 字节(可能含敏感 prompt), +/// body_hash 不参与小时聚合;剔除省流量(约 60%)且降低敏感数据外泄面。 +/// 返回每行 `{user, slot, status, tin, tout, ts, time, body_bytes}` 八个字段。 +pub fn read_day(day: &str) -> Result, String> { + if day.len() != 10 || day.as_bytes()[4] != b'-' || day.as_bytes()[7] != b'-' { + return Err(format!("日期格式错(期望 YYYY-MM-DD):{day}")); + } + let path = root().join(day).join("meta.jsonl"); + let file = fs::File::open(&path).map_err(|e| format!("{} 不存在或不可读:{e}", path.display()))?; + let reader = BufReader::new(file); + let mut out = Vec::new(); + for line in std::io::BufRead::lines(reader).flatten() { + if line.is_empty() { + continue; + } + if let Ok(mut v) = serde_json::from_str::(&line) { + if let Some(obj) = v.as_object_mut() { + // 剔除敏感 / 不需要字段 + obj.remove("excerpt"); + obj.remove("body_hash"); + } + out.push(v); + } + } + Ok(out) +} diff --git a/tests/llm/e2e.sh b/tests/llm/e2e.sh index 4a05be1..916cdf0 100755 --- a/tests/llm/e2e.sh +++ b/tests/llm/e2e.sh @@ -559,14 +559,13 @@ curl -s -b "$JAR" -X POST $API/api/admin/users/delete -H 'Content-Type: applicat -d "$(jbody username healthprobe)" >/dev/null echo -echo "【13】对话审计(meta.jsonl:账号/上游/状态 + 前 100 字节 excerpt + 全文 hash)" +echo "【13】对话审计(meta.jsonl:账号/上游/状态 + 智能 excerpt + 全文 hash)" AUDIT=$RUN/audit sleep 0.3 # 1.0.18 起不再把请求体复制进审计目录(旧版每请求 700 KB+),只写一行 meta。 -# 所以这里的断言从「有 N 个 body 文件」变成「有 N 行 meta,且**本轮没有新增** body 副本」。 -# 用「增量」而不是「绝对 0」:本机 .run/ 下可能还压着 1.0.17 及更早写下的上千个 -# *.json(且沙箱下不一定清得掉),绝对 0 会被历史残留判死;增量 0 才是这条断言 -# 真正要证明的事 —— 这些请求一个副本都没多写。 +# 1.0.27 起 excerpt 改为智能摘录:短请求保留原文;长请求解析 JSON 提取 +# model + 最后一个 user content(按字符截),跳过 context_management / tools +# 等结构噪声,输出 {"model":"…","content":"…"}。 meta_n() { cat "$AUDIT"/*/meta.jsonl 2>/dev/null | awk 'NF{n++} END{print n+0}'; } body_files() { find "$AUDIT" -name '*.json' 2>/dev/null | wc -l | tr -d ' '; } BODY_BASE=$(body_files) @@ -575,30 +574,43 @@ ck "转发的请求都落了 meta 行" yes "$([ "$N1" -ge 3 ] && echo yes || ech ck "meta 行记录账号/上游/状态" yes \ "$(grep -q '"user":"alice"' "$AUDIT"/*/meta.jsonl 2>/dev/null && grep -q '"slot":"openai"' "$AUDIT"/*/meta.jsonl && grep -q '"status":200' "$AUDIT"/*/meta.jsonl && echo yes || echo no)" -# ★ 长请求体:excerpt 必须恰好是「前 100 字节」,且**尾部内容不得落盘**。 -# 这是 1.0.18 的核心取舍(元数据 + 100 字符),必须证明它真的只截了 100 字节。 +# ★ 长请求体:1.0.27 智能摘录优先把 user content 摘出,跳过 context_management / tools。 +# 这条断言是 1.0.18 的核心取舍(元数据 + 摘要),现在升级为「摘要含用户内容、 +# 不含结构噪声」。 +# 测试用 400 字节 + 'AAA…' 占位 + 'ZZ_TAIL_MARK' 尾巴,确保 body_bytes > 100 走智能路径。 PAD=$(printf 'A%.0s' $(seq 1 400)) LBODY="{\"model\":\"gpt-4o\",\"messages\":[{\"role\":\"user\",\"content\":\"${PAD}ZZ_TAIL_MARK\"}]}" code -H "Authorization: Bearer $ALICE_KEY" -X POST $GW/openai/v1/chat/completions \ -H 'Content-Type: application/json' -d "$LBODY" >/dev/null sleep 0.3 -ck "★excerpt = 请求体前 100 字节" yes "$("$PY" -c " + +# 取这一笔长请求的 excerpt(按 body_bytes > 400 + user=alice + status=200 唯一定位) +EXCERPT=$("$PY" -c " import json, sys -body, files = sys.argv[1], sys.argv[2:] -# 选择器:这一笔长请求体 body_bytes > 400,其余转发请求都只有几十字节 → 唯一命中。 -# 不再用 excerpt 前缀做选择器:那样在 excerpt 被转义坏掉时连行都选不中, -# 断言会以「找不到行」而不是「内容不对」失败,掩盖真正的原因。 -# 取**最后**一条匹配(而不是第一条):审计目录里可能还留着 1.0.18 首版写下的 -# 双重编码行(同样是 body_bytes 472),它排序在前、会把第一条位置占掉。 -res = 'no' -for f in files: +for f in sys.argv[1:]: for l in open(f, encoding='utf-8'): d = json.loads(l) if d.get('user') == 'alice' and d.get('status') == 200 and d.get('body_bytes', 0) > 400: - res = 'yes' if d.get('excerpt') == body[:100] else 'no' -print(res) -" "$LBODY" "$AUDIT"/*/meta.jsonl 2>/dev/null)" -ck "★body_bytes = 请求体真实长度" "$(printf '%s' "$LBODY" | wc -c | tr -d ' ')" \ + print(d.get('excerpt','')) + sys.exit(0) +" "$AUDIT"/*/meta.jsonl 2>/dev/null) + +# ★ 智能摘录:长请求 excerpt 是 {"model":"…","content":""} 结构 +# - 必须含 model 字段(保留诊断价值) +# - 必须含 user content 关键片段(跳过结构噪声,摘出真正想问的) +# - 不应含 'ZZ_TAIL_MARK'(尾部内容仍未落盘) +# - 不应含 AAA 占位(这是 user content,智能摘录**全部** user 内容到 content 字段; +# 原 1.0.18 前 100 字节全是结构噪声反而看不到 AAA) +ck "★智能 excerpt 含 model 字段" yes \ + "$(printf '%s' "$EXCERPT" | grep -q '"model":"gpt-4o"' && echo yes || echo no)" +ck "★智能 excerpt 含 user content(AAA 占位)" yes \ + "$(printf '%s' "$EXCERPT" | grep -q 'AAAA' && echo yes || echo no)" +ck "★智能 excerpt 不含尾部标记(脱敏与不落盘)" yes \ + "$(if printf '%s' "$EXCERPT" | grep -q 'ZZ_TAIL_MARK'; then echo no; else echo yes; fi)" +ck "★智能 excerpt 不含结构噪声(context_management / tools)" yes \ + "$(if printf '%s' "$EXCERPT" | grep -q 'context_management\|\"tools\"'; then echo no; else echo yes; fi)" + +ck "★body_bytes = 请求体真实长度(智能摘录不影响)" "$(printf '%s' "$LBODY" | wc -c | tr -d ' ')" \ "$("$PY" -c " import json, sys n = '' @@ -609,7 +621,7 @@ for f in sys.argv[1:]: n = d['body_bytes'] print(n) " "$AUDIT"/*/meta.jsonl 2>/dev/null)" -ck "★body_hash 是全文指纹(16 hex)" yes "$("$PY" -c " +ck "★body_hash 是全文指纹(16 hex,智能摘录不影响)" yes "$("$PY" -c " import json, re, sys res = 'no' for f in sys.argv[1:]: @@ -620,9 +632,34 @@ for f in sys.argv[1:]: print(res) " "$AUDIT"/*/meta.jsonl 2>/dev/null)" ck "★不再生成请求体副本(本轮新增 *.json = 0)" 0 "$(( $(body_files) - BODY_BASE ))" -ck "★审计目录里搜不到请求体尾部(只截 100 字节)" yes \ +ck "★审计目录里搜不到请求体尾部" yes \ "$(if grep -q 'ZZ_TAIL_MARK' "$AUDIT"/*/meta.jsonl 2>/dev/null; then echo no; else echo yes; fi)" +# ★ 短请求体(≤ 100B):excerpt 应保留原文(含 model + messages 结构) +SBODY="{\"model\":\"gpt-4o\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}]}" +code -H "Authorization: Bearer $ALICE_KEY" -X POST $GW/openai/v1/chat/completions \ + -H 'Content-Type: application/json' -d "$SBODY" >/dev/null +sleep 0.3 +# ⚠️ meta.jsonl 里 excerpt 是 JSON 字符串,其内的 "messages" 被转义成 \"messages\"—— +# 直接 grep '"messages"' 匹不到;用不带引号的 'messages' 即可(包含 messages 数组外层 +# + content 里的 messages 都不会误匹,下面 JSON 解析做严格断言)。 +ck "★短请求(≤100B)excerpt 保留原文(含 messages 结构)" yes \ + "$("$PY" -c " +import json, sys +res = 'no' +for f in sys.argv[1:]: + for l in open(f, encoding='utf-8'): + d = json.loads(l) + if d.get('user') != 'alice' or d.get('status') != 200 or d.get('body_bytes', 0) > 100: + continue + # 短请求 excerpt 应该是原文(含 messages 数组);智能摘录只摘 model + content + try: + ex = json.loads(d.get('excerpt','')) + if 'messages' in ex: res = 'yes' + except Exception: pass +print(res) +" "$AUDIT"/*/meta.jsonl 2>/dev/null)" + N2=$(meta_n) code -H "Authorization: Bearer sk_deadbeef" -X POST $GW/openai/v1/chat/completions \ -H 'Content-Type: application/json' -d "$BODY" >/dev/null