mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
fix: avoid rate-limit false positives in likely overflow detection
This commit is contained in:
committed by
Tak Hoffman
parent
883a638e49
commit
86a7ecb45e
@@ -30,6 +30,8 @@ describe("isLikelyContextOverflowError", () => {
|
||||
"too many requests",
|
||||
"429 Too Many Requests",
|
||||
"exceeded your current quota",
|
||||
"This request would exceed your account's rate limit",
|
||||
"429 Too Many Requests: request exceeds rate limit",
|
||||
];
|
||||
for (const sample of samples) {
|
||||
expect(isLikelyContextOverflowError(sample)).toBe(false);
|
||||
|
||||
@@ -38,7 +38,9 @@ export function isContextOverflowError(errorMessage?: string): boolean {
|
||||
|
||||
const CONTEXT_WINDOW_TOO_SMALL_RE = /context window.*(too small|minimum is)/i;
|
||||
const CONTEXT_OVERFLOW_HINT_RE =
|
||||
/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|(?:prompt|request|input).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i;
|
||||
/context.*overflow|context window.*(too (?:large|long)|exceed|over|limit|max(?:imum)?|requested|sent|tokens)|prompt.*(too (?:large|long)|exceed|over|limit|max(?:imum)?)|(?:request|input).*(?:context|window|length|token).*(too (?:large|long)|exceed|over|limit|max(?:imum)?)/i;
|
||||
const RATE_LIMIT_HINT_RE =
|
||||
/rate limit|too many requests|requests per (?:minute|hour|day)|quota|throttl|429\b/i;
|
||||
|
||||
export function isLikelyContextOverflowError(errorMessage?: string): boolean {
|
||||
if (!errorMessage) {
|
||||
@@ -56,6 +58,9 @@ export function isLikelyContextOverflowError(errorMessage?: string): boolean {
|
||||
if (isContextOverflowError(errorMessage)) {
|
||||
return true;
|
||||
}
|
||||
if (RATE_LIMIT_HINT_RE.test(errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
return CONTEXT_OVERFLOW_HINT_RE.test(errorMessage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user