fix: recognize OpenAI context_length_exceeded errors (#47954)

This commit is contained in:
shrey-berri 2026-10-23 10:09:39 -07:00 • committed by GitHub
parent 3188c6ba6a
commit bc18e10f6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 0 deletions

View file

@ -102,6 +102,7 @@ class ExceptionCheckers:
"`inputs` tokens + `max_new_tokens` must be",
"exceeds the available context size", # llama.cpp/Lemonade
"exceeds the maximum number of tokens allowed", # Gemini
'"code": "context_length_exceeded"',
]
for substring in known_exception_substrings:
if substring in _error_str_lowercase:

View file

@ -160,6 +160,12 @@ def test_api_base_line_keeps_an_at_sign_in_the_path(api_base: str) -> None:
# Tuple format: (error_message, expected_result)
context_window_test_cases = [
# Positive cases (should return True)
(
'"{\n "error": {\n "message": "Your input exceeds the context window of this model. '
'Please adjust your input and try again.",\n "type": "invalid_request_error",\n'
' "param": "input",\n "code": "context_length_exceeded"\n }\n}"',
True,
),
(
"An error occurred: The input exceeds the model's maximum context limit of 8192 tokens.",
True,