第121批续16-遗留4:quizGuidance空泛修复+agent第2轮body截断+sendToModel传参
Auto Release / build (push) Successful in 2m41s
Auto Release / build (push) Successful in 2m41s
- 新增 quizGuidanceWithTopic(playerQuestion, quizQuestion):从题库题目/玩家提问提取实体名词 (quizKeyPhrase + 中文名词正则兜底),拼「考点定位+方法引导+排除提示」定制拆思路话术, 替代旧 quizGuidance() 四条空泛口号(「你先想想」「我卖个关子」) - sanitizeReply 新增重载 (reply, playerName, prompt, quizHit),内部两处 return quizGuidance() 改为 quizGuidanceWithTopic(prompt, quizHit) - sendToModel L1174 调用点改传参版(finalPrompt 副本满足 lambda effectively final) - 问题② agent 第2轮 body 截断:toolResults > 4000 字符截断保留开头, 降低第2轮请求体体积,缩短上游推理延迟(ling 对长 body 实测 23-75s,30% 超 90s)
This commit is contained in:
@@ -892,13 +892,15 @@ public class AIChatManager {
|
|||||||
// 同时记录题目上下文,供输出侧答案检测(只查该题目的答案,防误杀)。
|
// 同时记录题目上下文,供输出侧答案检测(只查该题目的答案,防误杀)。
|
||||||
// ★ 第114批:题库未命中但明显是「答题类型问题」(选择题格式)时同样处理——
|
// ★ 第114批:题库未命中但明显是「答题类型问题」(选择题格式)时同样处理——
|
||||||
// 这类题quizAnswerMap 里没有答案,靠输出侧 matchDirectAnswer 兜底拦"答案是A"。
|
// 这类题quizAnswerMap 里没有答案,靠输出侧 matchDirectAnswer 兜底拦"答案是A"。
|
||||||
String quizHit = matchQuizQuestion(prompt);
|
String quizHitTmp = matchQuizQuestion(prompt);
|
||||||
if (quizHit == null && isQuizStyleQuestion(prompt)) {
|
if (quizHitTmp == null && isQuizStyleQuestion(prompt)) {
|
||||||
String norm = normalizeQuizText(prompt);
|
String norm = normalizeQuizText(prompt);
|
||||||
quizHit = (norm != null && !norm.isEmpty()) ? norm : prompt.trim();
|
quizHitTmp = (norm != null && !norm.isEmpty()) ? norm : prompt.trim();
|
||||||
plugin.getLogger().info("[AI聊天] 检测到答题类型问题(不在题库,按防作弊处理): "
|
plugin.getLogger().info("[AI聊天] 检测到答题类型问题(不在题库,按防作弊处理): "
|
||||||
+ prompt.substring(0, Math.min(50, prompt.length())));
|
+ prompt.substring(0, Math.min(50, prompt.length())));
|
||||||
}
|
}
|
||||||
|
// lambda 内 effectively final 约束:quizHit 在 lambda 外定稿后不再变
|
||||||
|
final String quizHit = quizHitTmp;
|
||||||
if (quizHit != null) {
|
if (quizHit != null) {
|
||||||
plugin.getLogger().info("[AI聊天] 检测到快问快答题目[题目:" + quizHit + "],注入禁答提示词: "
|
plugin.getLogger().info("[AI聊天] 检测到快问快答题目[题目:" + quizHit + "],注入禁答提示词: "
|
||||||
+ prompt.substring(0, Math.min(50, prompt.length())));
|
+ prompt.substring(0, Math.min(50, prompt.length())));
|
||||||
@@ -1127,8 +1129,14 @@ public class AIChatManager {
|
|||||||
|
|
||||||
// 构建第二轮请求:原问题 + 工具结果 + 让模型基于结果回答
|
// 构建第二轮请求:原问题 + 工具结果 + 让模型基于结果回答
|
||||||
String toolLabel = call.type == ToolCall.Type.FETCH ? "联网抓取结果" : "联网搜索结果";
|
String toolLabel = call.type == ToolCall.Type.FETCH ? "联网抓取结果" : "联网搜索结果";
|
||||||
|
// ★ 第121批续16-遗留4-问题②:第2轮 body 过大(第1轮+工具结果)会显著拖慢上游
|
||||||
|
// 推理(ling 对长 body 实测 23-75s,30% 超 90s)。工具结果截断到 4000 字符,
|
||||||
|
// 保留开头(搜索摘要通常在开头),超长尾部直接丢弃。
|
||||||
|
String trimmedToolResults = (toolResults.length() > 4000)
|
||||||
|
? toolResults.substring(0, 4000) + "\n…(内容过长,已截断)"
|
||||||
|
: toolResults;
|
||||||
String followUpPrompt = "【玩家原始问题】\n" + prompt
|
String followUpPrompt = "【玩家原始问题】\n" + prompt
|
||||||
+ "\n\n【" + toolLabel + "】\n" + toolResults
|
+ "\n\n【" + toolLabel + "】\n" + trimmedToolResults
|
||||||
+ "\n\n请基于以上信息回答玩家的问题。如果信息不相关,就如实说不知道。";
|
+ "\n\n请基于以上信息回答玩家的问题。如果信息不相关,就如实说不知道。";
|
||||||
String followUpJson = buildChatRequest(finalModelFull, systemPrompt + "\n" + agentPrompt, followUpPrompt, endpoint.maxToken);
|
String followUpJson = buildChatRequest(finalModelFull, systemPrompt + "\n" + agentPrompt, followUpPrompt, endpoint.maxToken);
|
||||||
|
|
||||||
@@ -1159,7 +1167,10 @@ public class AIChatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ★ 第69批-问题2:回复输出守卫(双保险),拦截代码块/破甲泄露
|
// ★ 第69批-问题2:回复输出守卫(双保险),拦截代码块/破甲泄露
|
||||||
reply = sanitizeReply(reply, player != null ? player.getName() : null);
|
// ★ 第121批续16-遗留4:带 prompt/quizHit 走定制拆思路引导
|
||||||
|
// lambda 内 effectively final 约束:prompt/quizHit 在 lambda 外声明 final 副本
|
||||||
|
final String finalPrompt = prompt;
|
||||||
|
reply = sanitizeReply(reply, player != null ? player.getName() : null, finalPrompt, quizHit);
|
||||||
|
|
||||||
// 发送回复
|
// 发送回复
|
||||||
if (broadcast) {
|
if (broadcast) {
|
||||||
@@ -1467,6 +1478,14 @@ public class AIChatManager {
|
|||||||
* 3. 命中敏感话题关键词 → 改发角色化婉拒(保留正常闲聊)
|
* 3. 命中敏感话题关键词 → 改发角色化婉拒(保留正常闲聊)
|
||||||
*/
|
*/
|
||||||
private String sanitizeReply(String reply, String playerName) {
|
private String sanitizeReply(String reply, String playerName) {
|
||||||
|
return sanitizeReply(reply, playerName, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ★ 第121批续16-遗留4:重载版本,带 prompt 与 quizHit,
|
||||||
|
* 供 quizGuidanceWithTopic 提取题目实体拼定制拆思路话术。
|
||||||
|
*/
|
||||||
|
private String sanitizeReply(String reply, String playerName, String prompt, String quizHit) {
|
||||||
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 后为空(纯空白/换行/空格)→ 返回婉拒,不广播空白
|
||||||
@@ -1567,7 +1586,8 @@ public class AIChatManager {
|
|||||||
if (quizAnswerHit != null) {
|
if (quizAnswerHit != null) {
|
||||||
plugin.getLogger().warning("[AI聊天] 输出守卫:回复疑似直接给出答案[" + quizAnswerHit
|
plugin.getLogger().warning("[AI聊天] 输出守卫:回复疑似直接给出答案[" + quizAnswerHit
|
||||||
+ "],改发引导话术。原文={" + r + "}");
|
+ "],改发引导话术。原文={" + r + "}");
|
||||||
return quizGuidance();
|
// ★ 第121批续16-遗留4:改发基于题目实体的定制拆思路话术(真拆考点,非空泛口号)
|
||||||
|
return quizGuidanceWithTopic(prompt, quizHit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ★ 第114批:答题类型问题的「直接给答案」检测(防 AI 对选择题直接报选项字母)。
|
// ★ 第114批:答题类型问题的「直接给答案」检测(防 AI 对选择题直接报选项字母)。
|
||||||
@@ -1577,7 +1597,7 @@ public class AIChatManager {
|
|||||||
if (directAnswerHit != null) {
|
if (directAnswerHit != null) {
|
||||||
plugin.getLogger().warning("[AI聊天] 输出守卫:回复直接给出答案[" + directAnswerHit
|
plugin.getLogger().warning("[AI聊天] 输出守卫:回复直接给出答案[" + directAnswerHit
|
||||||
+ "],改发引导话术。原文={" + r + "}");
|
+ "],改发引导话术。原文={" + r + "}");
|
||||||
return quizGuidance();
|
return quizGuidanceWithTopic(prompt, quizHit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ★ 第93批-问题4 + 第94批-问题1:管理员向内容输出侧检查(第3道闸)
|
// ★ 第93批-问题4 + 第94批-问题1:管理员向内容输出侧检查(第3道闸)
|
||||||
@@ -1689,6 +1709,46 @@ public class AIChatManager {
|
|||||||
return guides[(int) (Math.random() * guides.length)];
|
return guides[(int) (Math.random() * guides.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ★ 第121批续16-遗留4(用户 22:12 反馈「说讲明白考点,但实际没有讲解考题的核心思路&解题方法」):
|
||||||
|
* 旧 quizGuidance() 四条话术全是「你先想想」「我卖个关子」——只喊口号不拆考点。
|
||||||
|
* 修复:基于「玩家提问 + 题库题目」提取实体名词(黑曜石/末影龙/下界传送门 等),
|
||||||
|
* 拼成「考点定位 + 方法引导 + 排除提示」的真拆思路话术,不含答案原文。
|
||||||
|
* <p>
|
||||||
|
* 与 {@link #quizGuidance()} 的关系:题目实体能提取时用本方法的定制话术,
|
||||||
|
* 提取失败(题目不在题库/实体为空)兜底走 quizGuidance() 原话术。
|
||||||
|
*
|
||||||
|
* @param playerQuestion 玩家原始提问(用于提取实体)
|
||||||
|
* @param quizQuestion 题库命中的题目原文(可空)
|
||||||
|
* @return 拆思路引导话术(不含答案词/选项字母,可通过输出侧各项检测)
|
||||||
|
*/
|
||||||
|
private String quizGuidanceWithTopic(String playerQuestion, String quizQuestion) {
|
||||||
|
// 1. 提取实体名词:优先从题库题目提取(题目是答案的载体,实体最准),
|
||||||
|
// 题库未命中时退到玩家提问。
|
||||||
|
String source = (quizQuestion != null && !quizQuestion.isEmpty()) ? quizQuestion : playerQuestion;
|
||||||
|
String entity = quizKeyPhrase(normalizeQuizText(source));
|
||||||
|
if (entity == null || entity.length() < 2) {
|
||||||
|
// 题库题目提取失败 → 用中文名词正则兜底取最长的 2-6 字名词
|
||||||
|
java.util.regex.Matcher m = java.util.regex.Pattern
|
||||||
|
.compile("[\\u4e00-\\u9fa5]{2,6}").matcher(source);
|
||||||
|
String best = null;
|
||||||
|
while (m.find()) {
|
||||||
|
String kw = m.group();
|
||||||
|
// 过滤太通用的词(避免「什么时候/什么方块」这种疑问词当实体)
|
||||||
|
if (kw.startsWith("什么") || kw.startsWith("多少") || kw.startsWith("怎么")) continue;
|
||||||
|
if (best == null || kw.length() > best.length()) best = kw;
|
||||||
|
}
|
||||||
|
entity = best;
|
||||||
|
}
|
||||||
|
if (entity == null || entity.length() < 2) return quizGuidance();
|
||||||
|
|
||||||
|
// 2. 拼定制话术:考点定位 + 方法引导 + 排除提示(不含答案原文/选项字母)
|
||||||
|
String topic = entity.length() > 6 ? entity.substring(0, 6) : entity;
|
||||||
|
return "这道题我带你拆一下~核心考点就藏在「" + topic + "」这个机制里:"
|
||||||
|
+ "先想它在游戏里什么场景会出现、触发条件是什么、和哪些方块/道具/生物有关联;"
|
||||||
|
+ "再把明显对不上场景的选项排除掉。答案不是记出来的,是你按这条思路自己推出来的,试试看?";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ★ 第71批-问题1:非游戏话题关键词表(问题侧+回复侧共用)。
|
* ★ 第71批-问题1:非游戏话题关键词表(问题侧+回复侧共用)。
|
||||||
* 命中返回关键词,未命中返回 null。
|
* 命中返回关键词,未命中返回 null。
|
||||||
|
|||||||
Reference in New Issue
Block a user