mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
improved context window exceeding exception class
This commit is contained in:
@@ -11,12 +11,7 @@ class LLMContextLengthExceededException(Exception):
|
|||||||
|
|
||||||
def __init__(self, error_message: str):
|
def __init__(self, error_message: str):
|
||||||
self.original_error_message = error_message
|
self.original_error_message = error_message
|
||||||
if self._is_context_limit_error(error_message):
|
super().__init__(self._get_error_message(error_message))
|
||||||
super().__init__(self._get_error_message())
|
|
||||||
else:
|
|
||||||
raise ValueError(
|
|
||||||
"The provided error message is not related to context length limits."
|
|
||||||
)
|
|
||||||
|
|
||||||
def _is_context_limit_error(self, error_message: str) -> bool:
|
def _is_context_limit_error(self, error_message: str) -> bool:
|
||||||
return any(
|
return any(
|
||||||
@@ -24,8 +19,8 @@ class LLMContextLengthExceededException(Exception):
|
|||||||
for phrase in self.CONTEXT_LIMIT_ERRORS
|
for phrase in self.CONTEXT_LIMIT_ERRORS
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_error_message(self):
|
def _get_error_message(self, error_message: str):
|
||||||
return (
|
return (
|
||||||
f"LLM context length exceeded. Original error: {self.original_error_message}\n"
|
f"LLM context length exceeded. Original error: {error_message}\n"
|
||||||
"Consider using a smaller input or implementing a text splitting strategy."
|
"Consider using a smaller input or implementing a text splitting strategy."
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user