第58批续26修复:空模板内置供应商刷屏 + parseModelConfig 支持静默重读

根因1:models.json 里 内置供应商 条目是全空模板(供应商名字=''),
但 has("供应商名字") 返回 true → 被当有效内置供应商处理 →
每秒重读配置都拿空名字去 供应商.json 找 URL → 找不到 → 3条warning每秒刷屏。

根因2:quiet=true 的重读模式只静默了配置加载完成日志,
parseModelConfig 里的 warning 没加 quiet 判断 → 每秒刷屏。

修复:
1. parseModelConfig 加 quiet 参数,quiet 模式下跳过无效配置的 warning
2. 空供应商名字直接跳过(模板占位不算有效配置)
This commit is contained in:
youpaishidifu
2026-10-28 21:43:09 +08:00
parent 10fb36c47a
commit 89e6de4415
+14 -6
View File
@@ -153,7 +153,7 @@ public class AIChatManager {
JsonObject section1 = config.getAsJsonObject("1"); JsonObject section1 = config.getAsJsonObject("1");
if (section1.has("模型配置")) { if (section1.has("模型配置")) {
JsonObject modelConfig = section1.getAsJsonObject("模型配置"); JsonObject modelConfig = section1.getAsJsonObject("模型配置");
parseModelConfig(modelConfig); parseModelConfig(modelConfig, quiet);
} }
} }
@@ -259,7 +259,7 @@ public class AIChatManager {
} }
} }
private void parseModelConfig(JsonObject modelConfig) { private void parseModelConfig(JsonObject modelConfig, boolean quiet) {
// ★ 重读前清理,避免旧配置残留(putIfAbsent 不会覆盖已存在的键) // ★ 重读前清理,避免旧配置残留(putIfAbsent 不会覆盖已存在的键)
modelEndpoints.clear(); modelEndpoints.clear();
providerToModel.clear(); providerToModel.clear();
@@ -275,7 +275,7 @@ public class AIChatManager {
boolean isBuiltin = supplierConfig.has("供应商名字"); boolean isBuiltin = supplierConfig.has("供应商名字");
if (!isCustom && !isBuiltin) { if (!isCustom && !isBuiltin) {
plugin.getLogger().info("[AI聊天] 配置跳过[" + key + "]: 既无baseurl也无供应商名字"); if (!quiet) plugin.getLogger().info("[AI聊天] 配置跳过[" + key + "]: 既无baseurl也无供应商名字");
continue; continue;
} }
@@ -288,15 +288,23 @@ public class AIChatManager {
baseUrl = getStr(supplierConfig, "baseurl"); baseUrl = getStr(supplierConfig, "baseurl");
} else { } else {
String providerName = getStr(supplierConfig, "供应商名字"); String providerName = getStr(supplierConfig, "供应商名字");
// ★ 空模板(供应商名字='')不是有效配置:用户没配内置供应商,直接跳过
// 之前没有这个判断 → 每秒重读配置都拿空名字去找 URL → 3条warning刷屏
if (providerName == null || providerName.isEmpty()) {
if (!quiet) plugin.getLogger().info("[AI聊天] 配置跳过[" + key + "]: 内置供应商名字为空(模板占位,忽略)");
continue;
}
baseUrl = findProviderUrl(providerName); baseUrl = findProviderUrl(providerName);
if (baseUrl == null || baseUrl.isEmpty()) { if (baseUrl == null || baseUrl.isEmpty()) {
plugin.getLogger().warning("[AI聊天] 配置跳过[" + key + "]: 内置供应商 '" + providerName + "' 在 供应商.json 中找不到URL"); if (!quiet) {
plugin.getLogger().warning("[AI聊天] 诊断: 请确认 供应商.json 中存在路径 '" + providerName + "',且路径拼写完全正确"); plugin.getLogger().warning("[AI聊天] 配置跳过[" + key + "]: 内置供应商 '" + providerName + "' 在 供应商.json 中找不到URL");
plugin.getLogger().warning("[AI聊天] 诊断: 请确认 供应商.json 中存在路径 '" + providerName + "',且路径拼写完全正确");
}
} }
} }
if (baseUrl == null || baseUrl.isEmpty() || apiKey == null || apiKey.isEmpty()) { if (baseUrl == null || baseUrl.isEmpty() || apiKey == null || apiKey.isEmpty()) {
plugin.getLogger().warning("[AI聊天] 配置跳过[" + key + "]: baseUrl=" + baseUrl + ", apiKey=" + apiKey); if (!quiet) plugin.getLogger().warning("[AI聊天] 配置跳过[" + key + "]: baseUrl=" + baseUrl + ", apiKey=" + apiKey);
continue; continue;
} }