新增配置项,允许配置:超出最多携带对话数量 时,一次性丢弃多少条旧消息

This commit is contained in:
Raila23
2025-04-09 22:10:56 +08:00
parent f2cc4311c5
commit 0b381e2570
@@ -38,6 +38,9 @@ class LLMRequestSubStage(Stage):
self.max_context_length = ctx.astrbot_config["provider_settings"][
"max_context_length"
] # int
self.dequeue_context_length = ctx.astrbot_config["provider_settings"][
"dequeue_context_length"
] # int
self.streaming_response = ctx.astrbot_config["provider_settings"][
"streaming_response"
] # bool
@@ -135,7 +138,7 @@ class LLMRequestSubStage(Stage):
and len(req.contexts) // 2 > self.max_context_length
):
logger.debug("上下文长度超过限制,将截断。")
req.contexts = req.contexts[-self.max_context_length * 2 :]
req.contexts = req.contexts[-(self.max_context_length - self.dequeue_context_length) * 2 :]
# session_id
if not req.session_id: