From c6df820164e045175dfa2cb22d64877c261b326c Mon Sep 17 00:00:00 2001 From: Raila23 <3271405327@qq.com> Date: Sat, 12 Apr 2025 15:34:35 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E6=AF=8F=E6=AC=A1?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=9A=84=E6=B6=88=E6=81=AF=EF=BC=8C=E6=AF=94?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E4=B8=8A=E6=9C=9F=E6=9C=9B=E7=9A=84=E5=A4=9A?= =?UTF-8?q?1=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/process_stage/method/llm_request.py | 2 +- 1 file changed, 1 insertion(+), 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 617e458c8..90c7d6256 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -146,7 +146,7 @@ class LLMRequestSubStage(Stage): ): logger.debug("上下文长度超过限制,将截断。") req.contexts = req.contexts[ - -(self.max_context_length - self.dequeue_context_length) * 2 : + -(self.max_context_length - self.dequeue_context_length + 1) * 2 : ] # session_id From 2fe1f2060a61a22c5565cab3c08d1e2828e873f5 Mon Sep 17 00:00:00 2001 From: Raila23 <3271405327@qq.com> Date: Sat, 12 Apr 2025 16:26:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=B7=A5=E5=85=B7=E6=88=96=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=9C=AA=E7=9F=A5=E6=83=85=E5=86=B5=EF=BC=8C=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4400=20BadRequestError?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/process_stage/method/llm_request.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index 90c7d6256..fd70275d8 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -148,6 +148,10 @@ class LLMRequestSubStage(Stage): req.contexts = req.contexts[ -(self.max_context_length - self.dequeue_context_length + 1) * 2 : ] + # 找到第一个role 为 user 的索引,确保上下文格式正确 + index = next((i for i, item in enumerate(req.contexts) if item.get("role") == "user"), None) + if index is not None and index > 0: + req.contexts = req.contexts[index:] # session_id if not req.session_id: