mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
Merge branch 'main' into bugfix/litellm-plus-generic-excpetions
This commit is contained in:
@@ -139,7 +139,6 @@ Now let's get you set up! 🚀
|
|||||||
│ └── __init__.py
|
│ └── __init__.py
|
||||||
└── config/
|
└── config/
|
||||||
├── agents.yaml
|
├── agents.yaml
|
||||||
├── config.yaml
|
|
||||||
└── tasks.yaml
|
└── tasks.yaml
|
||||||
```
|
```
|
||||||
</Frame>
|
</Frame>
|
||||||
|
|||||||
@@ -149,33 +149,19 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
if self._is_context_length_exceeded(e):
|
if self._is_context_length_exceeded(e):
|
||||||
self._handle_context_length()
|
self._handle_context_length()
|
||||||
continue
|
continue
|
||||||
elif self._is_litellm_authentication_error(e):
|
|
||||||
self._handle_litellm_auth_error(e)
|
|
||||||
raise e
|
|
||||||
else:
|
else:
|
||||||
self._printer.print(
|
self._handle_unknown_error(e)
|
||||||
content=f"Unhandled exception: {e}",
|
raise e
|
||||||
color="red",
|
|
||||||
)
|
|
||||||
finally:
|
finally:
|
||||||
self.iterations += 1
|
self.iterations += 1
|
||||||
|
|
||||||
self._show_logs(formatted_answer)
|
self._show_logs(formatted_answer)
|
||||||
return formatted_answer
|
return formatted_answer
|
||||||
|
|
||||||
def _is_litellm_authentication_error(self, exception: Exception) -> bool:
|
def _handle_unknown_error(self, exception: Exception) -> None:
|
||||||
"""Check if the exception is a litellm authentication error."""
|
"""Handle unknown errors by informing the user."""
|
||||||
if LiteLLMAuthenticationError and isinstance(
|
|
||||||
exception, LiteLLMAuthenticationError
|
|
||||||
):
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def _handle_litellm_auth_error(self, exception: Exception) -> None:
|
|
||||||
"""Handle litellm authentication error by informing the user and exiting."""
|
|
||||||
self._printer.print(
|
self._printer.print(
|
||||||
content="Authentication error with litellm occurred. Please check your API key and configuration.",
|
content="An unknown error occurred. Please check the details below.",
|
||||||
color="red",
|
color="red",
|
||||||
)
|
)
|
||||||
self._printer.print(
|
self._printer.print(
|
||||||
|
|||||||
@@ -1638,13 +1638,13 @@ def test_litellm_auth_error_handling():
|
|||||||
|
|
||||||
|
|
||||||
def test_crew_agent_executor_litellm_auth_error():
|
def test_crew_agent_executor_litellm_auth_error():
|
||||||
"""Test that CrewAgentExecutor properly identifies and handles LiteLLM authentication errors."""
|
"""Test that CrewAgentExecutor handles LiteLLM authentication errors by raising them."""
|
||||||
from litellm import AuthenticationError as LiteLLMAuthenticationError
|
from litellm import AuthenticationError as LiteLLMAuthenticationError
|
||||||
|
|
||||||
from crewai.agents.tools_handler import ToolsHandler
|
from crewai.agents.tools_handler import ToolsHandler
|
||||||
from crewai.utilities import Printer
|
from crewai.utilities import Printer
|
||||||
|
|
||||||
# Create an agent and executor with max_retry_limit=0
|
# Create an agent and executor
|
||||||
agent = Agent(
|
agent = Agent(
|
||||||
role="test role",
|
role="test role",
|
||||||
goal="test goal",
|
goal="test goal",
|
||||||
@@ -1691,7 +1691,7 @@ def test_crew_agent_executor_litellm_auth_error():
|
|||||||
|
|
||||||
# Verify error handling
|
# Verify error handling
|
||||||
mock_printer.assert_any_call(
|
mock_printer.assert_any_call(
|
||||||
content="Authentication error with litellm occurred. Please check your API key and configuration.",
|
content="An unknown error occurred. Please check the details below.",
|
||||||
color="red",
|
color="red",
|
||||||
)
|
)
|
||||||
mock_printer.assert_any_call(
|
mock_printer.assert_any_call(
|
||||||
|
|||||||
Reference in New Issue
Block a user