refactor: MaxHistory + ReminderInterval in appsettings auslagern

- MaxHistory (Default: 120): Max History-Messages pro API-Request
- ReminderInterval (Default: 30): System-Prompt Reminder alle N Messages (0 = deaktiviert)
- Beide Werte über Server-Settings-UI konfigurierbar
- Hardcoded Werte in ChatService durch konfigurierbare Felder ersetzt
This commit is contained in:
Meleki committed 2026-03-09 07:03:47 +01:00
1 parent 42d366ea47
commit 57560cbbea
4 files changed
+18 -8

No files matched your search

+2
View File
@@ -25,6 +25,8 @@ public static class ServerSettingsEndpoint
new SettingDefinition("Port", "int", 19000, "Server-Port (erfordert Neustart)", "number"),
new SettingDefinition("AnthropicToken", "string", "", "Anthropic API Key", "password"),
new SettingDefinition("MaxIterations", "int", 100, "Max Tool-Loop Iterationen pro Chat", "number"),
new SettingDefinition("MaxHistory", "int", 120, "Max History-Messages pro Request", "number"),
new SettingDefinition("ReminderInterval", "int", 30, "System-Prompt Reminder alle N Messages (0 = deaktiviert)", "number"),
new SettingDefinition("PayloadLogging", "bool", false, "API-Payloads loggen (Debug)", "toggle"),
new SettingDefinition("PayloadLoggingGzip", "bool", false, "Payload-Logs als .gz komprimieren", "toggle"),
new SettingDefinition("KreaToken", "string", "", "Krea API Token", "password"),
+3 -1
View File
@@ -30,7 +30,9 @@ builder.Services.AddSingleton(skillService);
// Shared Services
var toolService = new ToolService();
builder.Services.AddSingleton(toolService);
var chatService = new ChatService(dbService, toolService, memoryService, skillService);
var maxHistory = builder.Configuration.GetValue<int>("MaxHistory", 120);
var reminderInterval = builder.Configuration.GetValue<int>("ReminderInterval", 30);
var chatService = new ChatService(dbService, toolService, memoryService, skillService, maxHistory, reminderInterval);
builder.Services.AddSingleton(chatService);
// AnthropicService (Singleton – shared zwischen ChatEndpoint und TelegramService)
+11 -7
View File
@@ -14,13 +14,18 @@ public class ChatService
private readonly ToolService _toolService;
private readonly MemoryService _memoryService;
private readonly SkillService _skillService;
private readonly int _maxHistory;
private readonly int _reminderInterval;
public ChatService(DatabaseService db, ToolService toolService, MemoryService memoryService, SkillService skillService)
public ChatService(DatabaseService db, ToolService toolService, MemoryService memoryService, SkillService skillService,
int maxHistory = 120, int reminderInterval = 30)
{
_db = db;
_toolService = toolService;
_memoryService = memoryService;
_skillService = skillService;
_maxHistory = maxHistory;
_reminderInterval = reminderInterval;
}
public static string ResolveModelId(string model)
@@ -478,14 +483,13 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop?
}
}
// History auf maximal 120 Messages begrenzen (älteste entfernen)
const int maxHistory = 120;
if (history.Count > maxHistory)
history.RemoveRange(0, history.Count - maxHistory);
// History auf maximal N Messages begrenzen (älteste entfernen)
if (history.Count > _maxHistory)
history.RemoveRange(0, history.Count - _maxHistory);
// Reminder einfügen: alle ~30 user/assistant-Paare ein Reminder-Paar einfügen
var reminder = SystemPromptBuilder.BuildReminder(promptBlocks);
if (!string.IsNullOrWhiteSpace(reminder) && history.Count > 30)
if (!string.IsNullOrWhiteSpace(reminder) && _reminderInterval > 0 && history.Count > _reminderInterval)
{
var reminderUser = new Dictionary<string, object>
{
@@ -504,7 +508,7 @@ Für welche Plattform soll die App entwickelt werden? Web, Mobile oder Desktop?
for (int i = 0; i < history.Count; i++)
{
messageCount++;
if (messageCount > 0 && messageCount % 30 == 0)
if (messageCount > 0 && messageCount % _reminderInterval == 0)
{
// Position nach dem aktuellen Element – aber nur einfügen wenn es eine
// assistant-Message ist (damit user/assistant-Alternierung nicht bricht)
+2
View File
@@ -9,6 +9,8 @@
"Port": 19000,
"AnthropicToken": "",
"MaxIterations": 100,
"MaxHistory": 120,
"ReminderInterval": 30,
"PayloadLogging": false,
"PayloadLoggingGzip": false,
"KreaToken": "",