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:
1 parent
42d366ea47
commit
57560cbbea
4 files changed
+18
-8
No files matched your search
+11
-7
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user