已实现“设置里手动填写上下文保存长度(默认 10 万,最大 20 万)”:
新增设置项:Source/WulaFallenEmpire/WulaFallenEmpireSettings.cs 增加 maxContextTokens 并持久化。 设置界面:Source/WulaFallenEmpire/WulaFallenEmpireMod.cs 增加输入框(Widgets.TextFieldNumeric,范围 1000..200000)。 生效点:Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs 压缩历史时不再用常量 MaxHistoryTokens,改为读取 WulaFallenEmpireMod.settings.maxContextTokens。 文本:1.6/1.6/Languages/ChineseSimplified (简体中文)/Keyed/WULA_Keyed.xml 添加 Wula_AISettings_MaxContextTokens / Wula_AISettings_MaxContextTokensDesc。 已编译输出:1.6/1.6/Assemblies/WulaFallenEmpire.dll
This commit is contained in:
@@ -21,11 +21,17 @@ namespace WulaFallenEmpire.EventSystem.AI.UI
|
||||
private bool _scrollToBottom = false;
|
||||
private List<AITool> _tools = new List<AITool>();
|
||||
private Dictionary<int, Texture2D> _portraits = new Dictionary<int, Texture2D>();
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user