用户两条反馈(15:06-15:09):
1. TOOL 标记残留仍输出:日志「回复含 TOOL 标记残留,拦截」但 TOOL 标记还是发出来了。
根因:sanitizeReply 清洗正则 TOOL:(SEARCH|FETCH):[^\s]* 只匹配到第一个空格,
参数「末影龙 死亡 掉落 经验值 多少点 第一次 12000」含空格 → 只删「TOOL:SEARCH:末影龙」,
残留「死亡 掉落 经验值 多少点 第一次 12000」仍输出。
2. AI 直接答「末影龙...12000点经验」:命中题库第14题「末影龙被击败后掉落(12000)经验」,
但 matchQuizAnswer 对纯数字答案 a.matches("\d+") 直接 continue 跳过 → 没拦。
修复(AIChatManager.java):
1. TOOL 清洗正则改「匹配到行尾/换行」([^\n]*),agent 循环 L1105/L1136 同步改;
sanitizeReply 增删「→ 联网搜索」「→ 联网抓取」残留 + 清洗后仍含 TOOL 字样则 fallbackDodge。
2. matchQuizAnswer 纯数字答案不再无条件跳过:方向A(整段=数字)仍跳过防误杀,
方向B(有作弊意图+命中该题)加 hasQuestionContext——断言句含题目实体名词
(末影龙/刷怪箱 等 2-6 字子串)才拦数字答案;孤立数字(「16个苹果」)放行。
commit 后 touch jar → 双端 SFTP 部署。
This commit is contained in:
@@ -1102,7 +1102,8 @@ public class AIChatManager {
|
||||
// 改为:去掉 TOOL 标记后直接 break,让模型基于已有信息回答;
|
||||
// 如果回复里还残留 TOOL 标记,sanitizeReply 会拦截。
|
||||
// ★ 第77批-新bug:用 regex 替换,覆盖 arg 含中文/空格/特殊字符的情况
|
||||
reply = reply.replaceAll("TOOL:" + call.type.name() + ":[^\\s]*", "").trim();
|
||||
// ★ 第121批续23:删整行 TOOL 标记+参数(旧 [^\s]* 只删到空格,残留参数输出)
|
||||
reply = reply.replaceAll("TOOL:" + call.type.name() + ":[^\\n]*", "").trim();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1131,9 +1132,9 @@ public class AIChatManager {
|
||||
}
|
||||
String followUpReply = parseChatResponse(followUpResp.body());
|
||||
if (followUpReply == null) break;
|
||||
// ★ 第77批-新bug:过滤 TOOL 标记,只匹配标记本身+参数,不误删同行答案
|
||||
// 原 .* 会匹配到行尾,如果模型把答案写在 TOOL 标记同行会误删答案
|
||||
reply = followUpReply.replaceAll("TOOL:(SEARCH|FETCH):[^\\s]*", "").trim();
|
||||
// ★ 第77批-新bug / 第121批续23:删整行 TOOL 标记+参数(匹配到行尾/换行),
|
||||
// 覆盖参数含中文/空格多词的情况;保留行内 TOOL 标记后的中文答案。
|
||||
reply = followUpReply.replaceAll("TOOL:(SEARCH|FETCH):[^\\n]*", "").trim();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("[AI聊天-Agent] 第" + (agentRound + 1) + "轮请求异常: " + e.getMessage());
|
||||
break;
|
||||
@@ -1481,17 +1482,19 @@ public class AIChatManager {
|
||||
}
|
||||
|
||||
// ★ 第77批修复(#354):TOOL 标记残留拦截
|
||||
// 工具调用失败时模型可能仍输出 TOOL:SEARCH:关键词 标记,
|
||||
// 工具调用失败/超时后模型仍可能输出 TOOL:SEARCH:关键词 标记,
|
||||
// 或者第二轮请求的回复里残留 TOOL:FETCH: URL 标记
|
||||
if (r.contains("TOOL:SEARCH:") || r.contains("TOOL:FETCH:")) {
|
||||
plugin.getLogger().warning("[AI聊天] 输出守卫:回复含 TOOL 标记残留,拦截。原文={" + r + "}");
|
||||
// ★ 第77批-新bug:模型可能把内部过程描述写在 TOOL 标记同行
|
||||
// 例: "TOOL:SEARCH:关键词 一 联网搜索玩家问..."
|
||||
// 只删 TOOL 标记本身(标记+参数,不删同行答案),再删内部过程描述
|
||||
String cleaned = r.replaceAll("TOOL:(SEARCH|FETCH):[^\\s]*", "").trim();
|
||||
// 删除开头的「一/壹 联网搜索/查询/抓取」等内部过程描述
|
||||
// ★ 第121批续23:TOOL 标记参数可能含中文/空格/多词(如「末影龙 死亡 掉落 经验值 多少点」),
|
||||
// 旧正则 [^\s]* 只匹配到第一个空格就停 → 残留参数仍输出(用户反馈「依然输出出来了」)。
|
||||
// 改为匹配到行尾/换行/标记边界([\s]|$),把整行 TOOL 标记+参数删干净。
|
||||
// 保留行内 TOOL 标记后的中文答案(如「TOOL:SEARCH:xx 答案是yy」删标记留答案)。
|
||||
String cleaned = r.replaceAll("TOOL:(SEARCH|FETCH):[^\n]*", "").trim();
|
||||
// 删残留的「→ 联网搜索」「→ 联网抓取」「一/壹 联网/搜索/查询/抓取」等内部过程描述
|
||||
cleaned = cleaned.replaceAll("^[一壹]\\s*[联网查询搜索抓取获取]\\s*", "").trim();
|
||||
if (!cleaned.isEmpty() && !cleaned.equals(r)) {
|
||||
cleaned = cleaned.replaceAll("[→\\-]\\s*联网[搜索查询抓取获取][^\\n]*", "").trim();
|
||||
if (!cleaned.isEmpty() && !cleaned.equals(r) && !cleaned.contains("TOOL:SEARCH:") && !cleaned.contains("TOOL:FETCH:")) {
|
||||
return cleaned;
|
||||
}
|
||||
return fallbackDodge();
|
||||
@@ -2092,20 +2095,61 @@ public class AIChatManager {
|
||||
for (Map.Entry<String, String> e : quizAnswerMap.entrySet()) {
|
||||
String a = e.getValue();
|
||||
if (a == null || a.length() < 2) continue; // 单字符答案跳过(B/D/1)
|
||||
if (a.matches("\\d+")) continue; // 纯数字答案跳过(防误杀"16个")
|
||||
String question = e.getKey();
|
||||
boolean isNumber = a.matches("\\d+");
|
||||
// ★ 第121批续23:纯数字答案(12000/200 等)不再无条件跳过——
|
||||
// 旧逻辑直接 continue,导致 AI 答「末影龙...12000点经验」没被拦(用户命中第14题坐实)。
|
||||
// 数字答案只在「有作弊意图 + 该题上下文 + 断言句含数字」时拦(方向B),
|
||||
// 无上下文的孤立数字(如「16个」闲聊)仍放行防误杀。
|
||||
// 方向A:回复整段就是答案(严格,对所有玩家生效——回复整段=答案必是作弊)
|
||||
if (a.contains(norm)) return a;
|
||||
// 数字答案不做方向A(「12000」整段出现太可能是正常报数,易误杀),只做方向B。
|
||||
if (!isNumber && a.contains(norm)) return a;
|
||||
// 方向B:断言句里夹着答案原文(仅限有作弊意图的玩家,防误伤普通闲聊)
|
||||
if (assertive != null && intent.contains(e.getKey())) {
|
||||
if (assertive != null && intent.contains(question)) {
|
||||
for (String s : assertive) {
|
||||
String sn = normalizeQuizText(s);
|
||||
if (!sn.isEmpty() && sn.contains(a)) return a;
|
||||
if (sn.isEmpty()) continue;
|
||||
if (isNumber) {
|
||||
// ★ 数字答案:断言句含该数字 + 题目上下文词(末影龙/血量/经验/掉落等)才拦,
|
||||
// 避免「我有16个苹果」这类孤立数字误杀。
|
||||
if (sn.contains(a) && hasQuestionContext(sn, question)) return a;
|
||||
} else if (sn.contains(a)) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ★ 第121批续23:数字答案防误杀上下文判定。
|
||||
* 纯数字答案(12000/200)只在断言句里同时出现「题目上下文词」时才认定是答该题。
|
||||
* 上下文词 = 题目文本里的机制名词(末影龙/血量/经验/掉落/击杀 等),
|
||||
* 把题目按 4-8 字子串切出来,断言句命中任一子串即认定有上下文。
|
||||
* 孤立数字(「我有16个苹果」)无题目上下文词 → 放行不误杀。
|
||||
*
|
||||
* @param sentence 断言句归一化文本
|
||||
* @param question 题库题目原文(如「末影龙被击败后掉落(12000)经验」)
|
||||
* @return true = 断言句含题目上下文词(可认定在答该题)
|
||||
*/
|
||||
private boolean hasQuestionContext(String sentence, String question) {
|
||||
if (sentence == null || question == null) return false;
|
||||
String qs = normalizeQuizText(question);
|
||||
// 提取题目里的中文名词短语(2-6 字)作为上下文特征
|
||||
java.util.regex.Matcher m = java.util.regex.Pattern
|
||||
.compile("[\\u4e00-\\u9fa5]{2,6}").matcher(qs);
|
||||
while (m.find()) {
|
||||
String kw = m.group();
|
||||
// 过滤太通用的词(掉落/经验/击败 等高频词单列,避免「掉落」误杀正常掉落讨论)
|
||||
if (kw.equals("掉落") || kw.equals("经验") || kw.equals("击败")
|
||||
|| kw.equals("血量") || kw.equals("被")) continue;
|
||||
if (sentence.contains(kw)) return true;
|
||||
}
|
||||
// 兜底:题目里的实体名词(末影龙/刷怪箱 等)必须命中
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* ★ 第114批:把回复切成「断言句」列表(排除疑问/反问/引导句)。
|
||||
* 疑问句里出现答案词不算"给答案"——那是 AI 在引导玩家思考
|
||||
|
||||
Reference in New Issue
Block a user