diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll index 31601a33..27356288 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/1.6/Languages/ChineseSimplified (简体中文)/Keyed/WULA_Keyed.xml b/1.6/1.6/Languages/ChineseSimplified (简体中文)/Keyed/WULA_Keyed.xml index f93e6a24..ddc8a9e8 100644 --- a/1.6/1.6/Languages/ChineseSimplified (简体中文)/Keyed/WULA_Keyed.xml +++ b/1.6/1.6/Languages/ChineseSimplified (简体中文)/Keyed/WULA_Keyed.xml @@ -156,6 +156,8 @@ API 密钥: API 地址 (Base URL): 模型名称: + 上下文保存长度 (Token 估算上限): + 控制 AI 对话历史在超过上限时自动压缩。数值越小越省成本,但 AI 更容易“忘记”。 启用流式传输 (实验性) 启用实时打字机效果。如果遇到问题请禁用。 diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs index 5541cf55..90515475 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs @@ -21,11 +21,17 @@ namespace WulaFallenEmpire.EventSystem.AI.UI private bool _scrollToBottom = false; private List _tools = new List(); private Dictionary _portraits = new Dictionary(); - private const int MaxHistoryTokens = 100000; + private const int DefaultMaxHistoryTokens = 100000; private const int CharsPerToken = 4; private int _continuationDepth = 0; private const int MaxContinuationDepth = 6; + private static int GetMaxHistoryTokens() + { + int configured = WulaFallenEmpire.WulaFallenEmpireMod.settings?.maxContextTokens ?? DefaultMaxHistoryTokens; + return Math.Max(1000, Math.Min(200000, configured)); + } + // Static instance for tools to access public static Dialog_AIConversation Instance { get; private set; } @@ -467,7 +473,7 @@ When the player requests any form of resources, you MUST follow this multi-turn private void CompressHistoryIfNeeded() { int estimatedTokens = _history.Sum(h => h.message?.Length ?? 0) / CharsPerToken; - if (estimatedTokens > MaxHistoryTokens) + if (estimatedTokens > GetMaxHistoryTokens()) { int removeCount = _history.Count / 2; if (removeCount > 0) diff --git a/Source/WulaFallenEmpire/WulaFallenEmpireMod.cs b/Source/WulaFallenEmpire/WulaFallenEmpireMod.cs index 47481dea..f0cd6a9d 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpireMod.cs +++ b/Source/WulaFallenEmpire/WulaFallenEmpireMod.cs @@ -10,6 +10,7 @@ namespace WulaFallenEmpire public class WulaFallenEmpireMod : Mod { public static WulaFallenEmpireSettings settings; + private string _maxContextTokensBuffer; public WulaFallenEmpireMod(ModContentPack content) : base(content) { @@ -38,6 +39,12 @@ namespace WulaFallenEmpire listingStandard.Label("Wula_AISettings_Model".Translate()); settings.model = listingStandard.TextEntry(settings.model); + listingStandard.GapLine(); + listingStandard.Label("Wula_AISettings_MaxContextTokens".Translate()); + listingStandard.Label("Wula_AISettings_MaxContextTokensDesc".Translate()); + Rect tokensRect = listingStandard.GetRect(Text.LineHeight); + Widgets.TextFieldNumeric(tokensRect, ref settings.maxContextTokens, ref _maxContextTokensBuffer, 1000, 200000); + listingStandard.End(); base.DoSettingsWindowContents(inRect); } diff --git a/Source/WulaFallenEmpire/WulaFallenEmpireSettings.cs b/Source/WulaFallenEmpire/WulaFallenEmpireSettings.cs index d0ccbf64..04a0e90b 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpireSettings.cs +++ b/Source/WulaFallenEmpire/WulaFallenEmpireSettings.cs @@ -7,13 +7,15 @@ namespace WulaFallenEmpire public string apiKey = "sk-xxxxxxxx"; public string baseUrl = "https://api.deepseek.com"; public string model = "deepseek-chat"; + public int maxContextTokens = 100000; public override void ExposeData() { Scribe_Values.Look(ref apiKey, "apiKey", "sk-xxxxxxxx"); Scribe_Values.Look(ref baseUrl, "baseUrl", "https://api.deepseek.com"); Scribe_Values.Look(ref model, "model", "deepseek-chat"); + Scribe_Values.Look(ref maxContextTokens, "maxContextTokens", 100000); base.ExposeData(); } } -} \ No newline at end of file +}