Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class LLMContextLengthExceededException(Exception):
"too many tokens",
"input is too long",
"exceeds token limit",
"ContextWindowExceededError",
]

def __init__(self, error_message: str):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from crewai.utilities.exceptions.context_window_exceeding_exception import (
LLMContextLengthExceededException,
)


def test_context_window_error_detection():
"""Test detection of different context window error formats."""
assert LLMContextLengthExceededException("maximum context length exceeded")._is_context_limit_error(
"maximum context length exceeded"
)
assert LLMContextLengthExceededException("expected a string with maximum length")._is_context_limit_error(
"expected a string with maximum length"
)

litellm_error = "litellm.ContextWindowExceededError: litellm.BadRequestError: ContextWindowExceededError: MistralException - Error code: 400 - {'object': 'error', 'message': \"This model's maximum context lenght is 15000 tokens. However, you requested 15018 tokens (12970) in the messages, 2048 in the completion). Please reduce the length of the messages or completion.\", type: 'BadRequestError', 'param': None, 'code': 400}"

assert LLMContextLengthExceededException(litellm_error)._is_context_limit_error(
litellm_error
)
Loading