mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-23 07:51:33 +00:00
fix(embedded): classify model_context_window_exceeded as context overflow error
This commit is contained in:
@@ -269,6 +269,21 @@ describe("isContextOverflowError", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("matches model_context_window_exceeded stop reason surfaced by pi-ai", () => {
|
||||
// Anthropic API (and some OpenAI-compatible providers like ZhipuAI/GLM) return
|
||||
// stop_reason: "model_context_window_exceeded" when the context window is hit.
|
||||
// The pi-ai library surfaces this as "Unhandled stop reason: model_context_window_exceeded".
|
||||
const samples = [
|
||||
"Unhandled stop reason: model_context_window_exceeded",
|
||||
"model_context_window_exceeded",
|
||||
"context_window_exceeded",
|
||||
"Unhandled stop reason: context_window_exceeded",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isContextOverflowError(sample)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("matches Chinese context overflow error messages from proxy providers", () => {
|
||||
const samples = [
|
||||
"上下文过长",
|
||||
|
||||
@@ -105,6 +105,9 @@ export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
(lower.includes("max_tokens") && lower.includes("exceed") && lower.includes("context")) ||
|
||||
(lower.includes("input length") && lower.includes("exceed") && lower.includes("context")) ||
|
||||
(lower.includes("413") && lower.includes("too large")) ||
|
||||
// Anthropic API and OpenAI-compatible providers (e.g. ZhipuAI/GLM) return this stop reason
|
||||
// when the context window is exceeded. pi-ai surfaces it as "Unhandled stop reason: model_context_window_exceeded".
|
||||
lower.includes("context_window_exceeded") ||
|
||||
// Chinese proxy error messages for context overflow
|
||||
errorMessage.includes("上下文过长") ||
|
||||
errorMessage.includes("上下文超出") ||
|
||||
|
||||
Reference in New Issue
Block a user