From 909b4ad0640dab25d2b089b66a06704c6349f0ca Mon Sep 17 00:00:00 2001 From: leonforcode Date: Sat, 2 May 2026 12:17:52 +0800 Subject: [PATCH] fix: handle PPIO platform context-length error messages (#7888) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 压缩算法删除 user 消息 Bug 修复 * perf: improve truncate algo * fix: improve context length error detection for PPIO platform compatibility - Extend error detection to handle PPIO's error message format: 'The input is longer than the model's context length' - Add case-insensitive matching using .lower() for robustness - Maintain backward compatibility with existing 'maximum context length' check This fixes the issue where PPIO platform models (e.g., ppio/zai-org/glm-5-turbo) would fail with AgentState.ERROR due to unrecognized context length errors. --------- Co-authored-by: Soulter <905617992@qq.com> --- astrbot/core/provider/sources/openai_source.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index b8ee50203..64e3a6645 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -1076,7 +1076,7 @@ class ProviderOpenAIOfficial(Provider): image_fallback_used, ) raise e - if "maximum context length" in str(e): + if "maximum context length" in str(e) or "context length" in str(e).lower(): logger.warning( f"上下文长度超过限制。尝试弹出最早的记录然后重试。当前记录条数: {len(context_query)}", )