From 0b381e25708b55e5afc7aee55a48665d9d9b328d Mon Sep 17 00:00:00 2001 From: Raila23 <3271405327@qq.com> Date: Wed, 9 Apr 2025 22:10:56 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=EF=BC=8C=E5=85=81=E8=AE=B8=E9=85=8D=E7=BD=AE=EF=BC=9A?= =?UTF-8?q?=E8=B6=85=E5=87=BA=E6=9C=80=E5=A4=9A=E6=90=BA=E5=B8=A6=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=95=B0=E9=87=8F=20=E6=97=B6=EF=BC=8C=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=80=A7=E4=B8=A2=E5=BC=83=E5=A4=9A=E5=B0=91=E6=9D=A1?= =?UTF-8?q?=E6=97=A7=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/process_stage/method/llm_request.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index c6a87b37c..35e9f5f50 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -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: From 3d22772d4efbdeca4475ff0a4a9e19bdb3ed6853 Mon Sep 17 00:00:00 2001 From: Raila23 <3271405327@qq.com> Date: Wed, 9 Apr 2025 22:12:02 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B9=EF=BC=8C=E5=85=81=E8=AE=B8=E9=85=8D=E7=BD=AE=EF=BC=9A?= =?UTF-8?q?=E8=B6=85=E5=87=BA=E6=9C=80=E5=A4=9A=E6=90=BA=E5=B8=A6=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E6=95=B0=E9=87=8F=20=E6=97=B6=EF=BC=8C=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=80=A7=E4=B8=A2=E5=BC=83=E5=A4=9A=E5=B0=91=E6=9D=A1?= =?UTF-8?q?=E6=97=A7=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 13be0b498..fa1f70f34 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -50,6 +50,7 @@ DEFAULT_CONFIG = { "default_personality": "default", "prompt_prefix": "", "max_context_length": -1, + "dequeue_context_length": 1, "streaming_response": False, }, "provider_stt_settings": { @@ -994,6 +995,11 @@ CONFIG_METADATA_2 = { "type": "int", "hint": "超出这个数量时将丢弃最旧的部分,用户和AI的一轮聊天记为 1 条。-1 表示不限制,默认为不限制。", }, + "dequeue_context_length": { + "description": "丢弃对话数量(条)", + "type": "int", + "hint": "超出 最多携带对话数量(条) 时,丢弃多少条记录,用户和AI的一轮聊天记为 1 条。", + }, "streaming_response": { "description": "启用流式回复", "type": "bool", From 4d414a2994d41dc213250eee451bb4d469a22068 Mon Sep 17 00:00:00 2001 From: Raila23 <3271405327@qq.com> Date: Wed, 9 Apr 2025 22:28:33 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0dequeue=5Fcontext=5Flengt?= =?UTF-8?q?h=E7=9A=84=E5=80=BC=E7=9A=84=E5=88=A4=E6=96=AD=EF=BC=8C?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E5=9C=A81=E5=88=B0max=5Fcontext=5Flength?= =?UTF-8?q?=E4=B9=8B=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/process_stage/method/llm_request.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index 35e9f5f50..1ce44cee8 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -38,9 +38,10 @@ 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.dequeue_context_length = min( + max(1,ctx.astrbot_config["provider_settings"]["dequeue_context_length"]), + self.max_context_length - 1 + ) # int self.streaming_response = ctx.astrbot_config["provider_settings"][ "streaming_response" ] # bool From c0fadb45ab48ef465945d5e646d2d144a062e861 Mon Sep 17 00:00:00 2001 From: Raila23 <3271405327@qq.com> Date: Thu, 10 Apr 2025 15:20:56 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E8=AF=A6?= =?UTF-8?q?=E7=BB=86=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index fa1f70f34..32f77e7a5 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -998,7 +998,7 @@ CONFIG_METADATA_2 = { "dequeue_context_length": { "description": "丢弃对话数量(条)", "type": "int", - "hint": "超出 最多携带对话数量(条) 时,丢弃多少条记录,用户和AI的一轮聊天记为 1 条。", + "hint": "超出 最多携带对话数量(条) 时,丢弃多少条记录,用户和AI的一轮聊天记为 1 条。适宜的配置,可以提高超长上下文对话 deepseek 命中缓存效果,理想情况下计费将降低到1/3以下", }, "streaming_response": { "description": "启用流式回复",