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] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E8=B0=83=E7=94=A8=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=B7=A5=E5=85=B7=E6=88=96=E5=85=B6=E4=BB=96=E6=9C=AA?= =?UTF-8?q?=E7=9F=A5=E6=83=85=E5=86=B5=EF=BC=8C=E5=8F=AF=E8=83=BD=E5=AF=BC?= =?UTF-8?q?=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: