修复:调用函数工具或其他未知情况,可能导致400 BadRequestError

This commit is contained in:
Raila23
2025-04-12 16:26:02 +08:00
parent c6df820164
commit 2fe1f2060a
@@ -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: