Skip to content

Commit 09a1db3

Browse files
authored
fix(ai): recognize more context overflow errors (#57982)
1 parent ad5336e commit 09a1db3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎packages/ai/src/provider-error.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import { isRecord } from "./utils/record.js"
1717

1818
const patterns = [
1919
/prompt is too long/i,
20-
/input is too long for requested model/i,
20+
/input is too long for (?:the )?(?:requested|selected) model/i,
21+
// OpenCode Go
22+
/too large for the model'?s configured input limit/i,
2123
// Cloudflare Workers AI reports this as HTTP 413.
2224
/exceeded this model context window limit/i,
2325
/exceeds the context window/i,
@@ -44,8 +46,8 @@ const patterns = [
4446
/context[_ ]length[_ ]exceeded/i,
4547
/context length is only \d+ tokens/i,
4648
/input length.*exceeds.*context length/i,
47-
// Z.ai code 1261 arrives as `Prompt too long` or `Prompt 超长`.
48-
/prompt (?:too long|超长)/i,
49+
// Z.ai code 1261 arrives as `Prompt too long`, `Prompt exceeds max length` or `Prompt 超长`.
50+
/prompt (?:too long|exceeds max length|超长)/i,
4951
/too large for model with \d+ maximum context length/i,
5052
/prompt has [\d,]+ tokens?, but the configured context size is [\d,]+ tokens?/i,
5153
/model_context_window_exceeded/i,

‎packages/ai/test/provider-error.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ describe("provider error classification", () => {
1717
"Too many tokens",
1818
"Input validation error: `inputs` tokens + `max_new_tokens` must be <= 131073. Given: 600035 `inputs` tokens and 16 `max_new_tokens`",
1919
"Token limit exceeded",
20+
"Prompt exceeds max length",
21+
"The input is too long for the selected model.",
22+
"This text request is too large for the model's configured input limit.",
2023
]
2124

2225
expect(messages.every(isContextOverflow)).toBe(true)

0 commit comments

Comments
 (0)