kongdeqiang
2026-10-12 ccf1a44c001e233c158bd168dc2d0d96721af929
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.custom.webui.util;
 
public final class ReasoningLeakFilter {
 
    private ReasoningLeakFilter() {
    }
 
    /** 明确的推理标记短语,出现即高度可疑 */
    private static final String[] MARKERS = {
            "Thinking Process", "Let me ", "Let's ", "Wait,",
            "Analyze the Request", "one last check", "Let me double-check",
            "Hmm,", "Okay, the ", "*Wait", "Final Decision", "Evaluate Constraints"
    };
 
    /**
     * 判断整段文本是否属于推理泄漏。
     *
     * @param text 完整正文
     * @return true 表示判定为泄漏,调用方应丢弃
     */
    public static boolean looksLikeReasoning(String text) {
        if (text == null || text.isBlank()) {
            return false;
        }
        int markerHits = 0;
        for (String marker : MARKERS) {
            if (text.contains(marker)) {
                markerHits++;
            }
        }
        if (markerHits == 0) {
            return false;
        }
 
        // 中文占比高时基本可排除:这些标记词都是英文,
        // 中文正常回答不会出现,出现了多半是模型串了语言
        long chinese = text.chars().filter(c -> c >= 0x4E00 && c <= 0x9FFF).count();
        double chineseRatio = (double) chinese / Math.max(1, text.length());
 
        // 至少命中 2 个标记,或命中 1 个且几乎全英文
        return markerHits >= 2 || chineseRatio < 0.2;
    }
}