mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 16:22:49 +00:00
code cleanup, using click for cli asker
This commit is contained in:
@@ -7,6 +7,9 @@ from .parser import YamlParser
|
||||
from .printer import Printer
|
||||
from .prompts import Prompts
|
||||
from .rpm_controller import RPMController
|
||||
from .exceptions.context_window_exceeding_exception import (
|
||||
LLMContextLengthExceededException,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"Converter",
|
||||
@@ -19,4 +22,5 @@ __all__ = [
|
||||
"Prompts",
|
||||
"RPMController",
|
||||
"YamlParser",
|
||||
"LLMContextLengthExceededException",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
class LLMContextLengthExceededException(Exception):
|
||||
CONTEXT_LIMIT_ERRORS = [
|
||||
"maximum context length",
|
||||
"context length exceeded",
|
||||
"context window full",
|
||||
"too many tokens",
|
||||
"input is too long",
|
||||
"exceeds token limit",
|
||||
]
|
||||
|
||||
def __init__(self, error_message: str):
|
||||
self.original_error_message = error_message
|
||||
if self._is_context_limit_error(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:
|
||||
return any(
|
||||
phrase.lower() in error_message.lower()
|
||||
for phrase in self.CONTEXT_LIMIT_ERRORS
|
||||
)
|
||||
|
||||
def _get_error_message(self):
|
||||
return (
|
||||
f"LLM context length exceeded. Original error: {self.original_error_message}\n"
|
||||
"Consider using a smaller input or implementing a text splitting strategy."
|
||||
)
|
||||
8
src/crewai/utilities/exceptions/exception_aggregator.py
Normal file
8
src/crewai/utilities/exceptions/exception_aggregator.py
Normal file
@@ -0,0 +1,8 @@
|
||||
class ContextLengthExceeded(Exception):
|
||||
def __init__(self, exceptions):
|
||||
self.exceptions = exceptions
|
||||
super().__init__(self.__str__())
|
||||
|
||||
def __str__(self):
|
||||
error_messages = [str(e) for e in self.exceptions]
|
||||
return f"Multiple BadRequestExceptions occurred: {', '.join(error_messages)}"
|
||||
Reference in New Issue
Block a user