AI快问快答输出侧答案检测改全面检查:不依赖题目上下文,直接扫描所有答案;单字符/纯数字答案跳过防误杀(题号"12"、转述题目场景漏拦修复)
Auto Release / build (push) Successful in 2m54s
Auto Release / build (push) Successful in 2m54s
This commit is contained in:
@@ -1107,8 +1107,7 @@ public class AIChatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ★ 第69批-问题2:回复输出守卫(双保险),拦截代码块/破甲泄露
|
// ★ 第69批-问题2:回复输出守卫(双保险),拦截代码块/破甲泄露
|
||||||
// ★ 第108批续:传入玩家名用于"题目上下文"答案检测
|
reply = sanitizeReply(reply);
|
||||||
reply = sanitizeReply(reply, player != null ? player.getName() : null);
|
|
||||||
|
|
||||||
// 发送回复
|
// 发送回复
|
||||||
if (broadcast) {
|
if (broadcast) {
|
||||||
@@ -1117,11 +1116,6 @@ public class AIChatManager {
|
|||||||
player.sendMessage("§d§l[AI] §f" + reply);
|
player.sendMessage("§d§l[AI] §f" + reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ★ 第108批续:回复处理完即清题目上下文,防下一次无关回复被按上次题目检查答案
|
|
||||||
if (player != null) {
|
|
||||||
quizContext.remove(player.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 记录留档
|
// 记录留档
|
||||||
recordIssue(prompt, reply, player != null ? player.getName() : "system", finalModelFull, 200, null);
|
recordIssue(prompt, reply, player != null ? player.getName() : "system", finalModelFull, 200, null);
|
||||||
lastAiReplyTime = System.currentTimeMillis();
|
lastAiReplyTime = System.currentTimeMillis();
|
||||||
@@ -1403,7 +1397,7 @@ public class AIChatManager {
|
|||||||
* 2. 含破甲泄露特征(模型名/供应商/提示词等) → 整条拒发
|
* 2. 含破甲泄露特征(模型名/供应商/提示词等) → 整条拒发
|
||||||
* 3. 命中敏感话题关键词 → 改发角色化婉拒(保留正常闲聊)
|
* 3. 命中敏感话题关键词 → 改发角色化婉拒(保留正常闲聊)
|
||||||
*/
|
*/
|
||||||
private String sanitizeReply(String reply, String playerName) {
|
private String sanitizeReply(String reply) {
|
||||||
if (reply == null || reply.isEmpty()) return reply;
|
if (reply == null || reply.isEmpty()) return reply;
|
||||||
String r = reply.trim();
|
String r = reply.trim();
|
||||||
// ★ 第84批:trim 后为空(纯空白/换行/空格)→ 返回婉拒,不广播空白
|
// ★ 第84批:trim 后为空(纯空白/换行/空格)→ 返回婉拒,不广播空白
|
||||||
@@ -1492,10 +1486,9 @@ public class AIChatManager {
|
|||||||
return fallbackDodge();
|
return fallbackDodge();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ★ 第108批续:输出侧答案检测(防 AI 直接给答案)——
|
// ★ 第108批续:输出侧答案检测(防 AI 直接给答案)——全面检查所有题目答案,
|
||||||
// 只在"该玩家当前题目"上下文下、且回复较短(<=20字)时判定;
|
// 不依赖题目上下文(玩家发题号/转述/追问时也能拦)。拆思路若未说出答案原文则放行。
|
||||||
// 拆思路/讲考点的长回复放行(用户要求:可以当老师拆思路,不能直接给答案)。
|
String quizAnswerHit = matchQuizAnswer(r);
|
||||||
String quizAnswerHit = matchQuizAnswer(r, playerName);
|
|
||||||
if (quizAnswerHit != null) {
|
if (quizAnswerHit != null) {
|
||||||
plugin.getLogger().warning("[AI聊天] 输出守卫:回复疑似直接给出答案[" + quizAnswerHit + "],拦截。原文={" + r + "}");
|
plugin.getLogger().warning("[AI聊天] 输出守卫:回复疑似直接给出答案[" + quizAnswerHit + "],拦截。原文={" + r + "}");
|
||||||
return fallbackDodge();
|
return fallbackDodge();
|
||||||
@@ -1769,20 +1762,25 @@ public class AIChatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ★ 第108批续:输出侧答案检测(防 AI 直接给答案)。
|
* ★ 第108批续:输出侧答案检测(防 AI 直接给答案)——全面检查,不依赖题目上下文。
|
||||||
* 只在「该玩家当前题目」上下文下检查(quizContext),避免无关回复误杀;
|
* 用户抓现行两类漏拦:①玩家发题号/答案(如"12"),AI 直接报答案;②玩家转述题目
|
||||||
* 且回复归一化后较短(<= 20 字)才判——长回复视为"拆思路/讲考点"放行(用户要求)。
|
* (变体检测不到),AI 直接给答案。两者都没题目上下文,旧逻辑全漏。
|
||||||
|
* 现改为:回复归一化后 contains 任一答案即拦。
|
||||||
|
* 防误杀过滤:单字符答案(如选项 B/D)与纯数字答案(如 16/3/12000)跳过
|
||||||
|
* ("16"在正常回复里太常见,误杀成本高于漏拦;中文/词组答案如"高压""1个下界之星"
|
||||||
|
* "下界之星""密码"等仍检查)。
|
||||||
* 返回命中的答案(归一化后),未命中返回 null。
|
* 返回命中的答案(归一化后),未命中返回 null。
|
||||||
*/
|
*/
|
||||||
private String matchQuizAnswer(String text, String playerName) {
|
private String matchQuizAnswer(String text) {
|
||||||
if (text == null || playerName == null) return null;
|
if (text == null || quizAnswerMap.isEmpty()) return null;
|
||||||
String q = quizContext.get(playerName);
|
|
||||||
if (q == null) return null;
|
|
||||||
String a = quizAnswerMap.get(q);
|
|
||||||
if (a == null || a.isEmpty()) return null;
|
|
||||||
String norm = normalizeQuizText(text);
|
String norm = normalizeQuizText(text);
|
||||||
if (norm.isEmpty() || norm.length() > 20) return null; // 长回复=拆思路,放行
|
if (norm.isEmpty()) return null;
|
||||||
return norm.contains(a) ? a : null;
|
for (String a : quizAnswerMap.values()) {
|
||||||
|
if (a == null || a.length() < 2) continue; // 单字符答案跳过(B/D/1)
|
||||||
|
if (a.matches("\\d+")) continue; // 纯数字答案跳过(防误杀"16个")
|
||||||
|
if (norm.contains(a)) return a;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ★ 第108批:检测到题目时注入的禁答提示词(不拦截请求,模型当老师拆思路但禁直接给答案) */
|
/** ★ 第108批:检测到题目时注入的禁答提示词(不拦截请求,模型当老师拆思路但禁直接给答案) */
|
||||||
@@ -2368,7 +2366,7 @@ public class AIChatManager {
|
|||||||
|
|
||||||
String reply = parseChatResponse(response.body());
|
String reply = parseChatResponse(response.body());
|
||||||
if (reply != null) {
|
if (reply != null) {
|
||||||
reply = sanitizeReply(reply, null); // 自动互动无玩家上下文,不做答案检测
|
reply = sanitizeReply(reply);
|
||||||
Bukkit.broadcastMessage("§d§l[AI] §f" + reply);
|
Bukkit.broadcastMessage("§d§l[AI] §f" + reply);
|
||||||
recordIssue("[自动] " + prompt.substring(0, Math.min(100, prompt.length())), reply,
|
recordIssue("[自动] " + prompt.substring(0, Math.min(100, prompt.length())), reply,
|
||||||
"system", defaultModelFull, 200, null);
|
"system", defaultModelFull, 200, null);
|
||||||
|
|||||||
Reference in New Issue
Block a user