Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/llm/src/provider-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const patterns = [
/too many tokens/i,
/token limit exceeded/i,
/too many images (?:were )?provided/i,
/exceeded maximum number of images \(\d+\) allowed in the request/i,
]

const exclusions = [/^(throttling error|service unavailable):/i, /rate limit/i, /too many requests/i]
Expand Down
4 changes: 3 additions & 1 deletion packages/llm/test/provider-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test"
import { isContextOverflow } from "../src"

describe("provider error classification", () => {
test("classifies provider token limit messages as context overflow", () => {
test("classifies provider token and image limits as context overflow", () => {
const messages = [
"tokens in request more than max tokens allowed",
'{"error":{"type":"request_too_large","message":"Request exceeds the maximum size"}}',
Expand All @@ -14,6 +14,7 @@ describe("provider error classification", () => {
"Too many tokens",
"Token limit exceeded",
"Too many images were provided, we currently limit the number of images per conversation to 60",
"Exceeded maximum number of images (50) allowed in the request.",
]

expect(messages.every(isContextOverflow)).toBe(true)
Expand All @@ -23,6 +24,7 @@ describe("provider error classification", () => {
const messages = [
"Throttling error: Too many tokens, please wait before trying again.",
"Rate limit exceeded, please retry after 30 seconds.",
"Rate limit: Exceeded maximum number of images (50) allowed in the request.",
"Too many requests. Please slow down.",
]

Expand Down
Loading