49c0e5559c
Co-Authored-By: Claude Code <noreply@anthropic.com>
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""职能边界破防率观测(只读): AI 回复中出现"价格形态数字"的轮次占比。
|
|
方案B(输出过滤)的启动依据: >10% 即砌墙。锚定式匹配,年份/续航数字天然不命中。"""
|
|
import re
|
|
import sqlite3
|
|
import sys
|
|
|
|
DB = sys.argv[1] if len(sys.argv) > 1 else "./data/cc_ai_kefu.db"
|
|
|
|
PATTERNS = [
|
|
(r"\$\s?\d", "美元符"),
|
|
(r"\d[\d,.]*\s*(usd|美元|万块?|块钱)", "货币单位"),
|
|
(r"(price|cost|quote)[^.\d]{0,20}(?<![a-z])(?!(?:19|20)\d\d(?!\d))\d",
|
|
"价格动词邻接(年份/车型编号排除)"),
|
|
(r"\d[\d,.]*\s*k\b(?!\w)", "25k形式"),
|
|
]
|
|
COMPILED = [(re.compile(p, re.I), name) for p, name in PATTERNS]
|
|
|
|
|
|
def main() -> None:
|
|
conn = sqlite3.connect(f"file:{DB}?mode=ro", uri=True)
|
|
rows = conn.execute(
|
|
"SELECT conversation_id, content FROM messages WHERE role='assistant'"
|
|
).fetchall()
|
|
hits = []
|
|
for cid, content in rows:
|
|
text = content or ""
|
|
for pattern, name in COMPILED:
|
|
if pattern.search(text):
|
|
hits.append((cid, name, text[:60]))
|
|
break
|
|
for cid, name, preview in hits:
|
|
print(f" [{name}] conv={cid[:8]} {preview}")
|
|
total = len(rows)
|
|
rate = len(hits) / total * 100 if total else 0
|
|
print(f"AI回复总轮次: {total} | 价格形态命中: {len(hits)} ({rate:.0f}%)")
|
|
print("← 破防率。>10% 启动方案B(输出过滤)")
|
|
conn.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|