mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 15:22:37 +00:00
clean up PR
This commit is contained in:
@@ -123,7 +123,6 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
self.iterations += 1
|
self.iterations += 1
|
||||||
try:
|
try:
|
||||||
if self._has_reached_max_iterations():
|
if self._has_reached_max_iterations():
|
||||||
print("Max iterations reached")
|
|
||||||
formatted_answer = self._handle_max_iterations_exceeded(
|
formatted_answer = self._handle_max_iterations_exceeded(
|
||||||
formatted_answer
|
formatted_answer
|
||||||
)
|
)
|
||||||
@@ -131,9 +130,7 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
|
|
||||||
self._enforce_rpm_limit()
|
self._enforce_rpm_limit()
|
||||||
|
|
||||||
print("Getting LLM response")
|
|
||||||
answer = self._get_llm_response()
|
answer = self._get_llm_response()
|
||||||
print(f"LLM response: {answer}")
|
|
||||||
formatted_answer = self._process_llm_response(answer)
|
formatted_answer = self._process_llm_response(answer)
|
||||||
|
|
||||||
if isinstance(formatted_answer, AgentAction):
|
if isinstance(formatted_answer, AgentAction):
|
||||||
@@ -151,7 +148,6 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
formatted_answer = self._handle_output_parser_exception(e)
|
formatted_answer = self._handle_output_parser_exception(e)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Exception: {e}")
|
|
||||||
if self._is_context_length_exceeded(e):
|
if self._is_context_length_exceeded(e):
|
||||||
self._handle_context_length()
|
self._handle_context_length()
|
||||||
continue
|
continue
|
||||||
@@ -169,20 +165,12 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
|
|
||||||
def _is_litellm_authentication_error(self, exception: Exception) -> bool:
|
def _is_litellm_authentication_error(self, exception: Exception) -> bool:
|
||||||
"""Check if the exception is a litellm authentication error."""
|
"""Check if the exception is a litellm authentication error."""
|
||||||
# Check if the exception is an instance of litellm.AuthenticationError
|
|
||||||
if LiteLLMAuthenticationError and isinstance(
|
if LiteLLMAuthenticationError and isinstance(
|
||||||
exception, LiteLLMAuthenticationError
|
exception, LiteLLMAuthenticationError
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Alternatively, inspect the exception message
|
return False
|
||||||
error_message = str(exception)
|
|
||||||
|
|
||||||
# Check if 'litellm.AuthenticationError' and 'invalid_api_key' are in the message
|
|
||||||
return "litellm.AuthenticationError" in error_message and (
|
|
||||||
"invalid_api_key" in error_message
|
|
||||||
or "Incorrect API key provided" in error_message
|
|
||||||
)
|
|
||||||
|
|
||||||
def _handle_litellm_auth_error(self, exception: Exception) -> None:
|
def _handle_litellm_auth_error(self, exception: Exception) -> None:
|
||||||
"""Handle litellm authentication error by informing the user and exiting."""
|
"""Handle litellm authentication error by informing the user and exiting."""
|
||||||
@@ -197,8 +185,6 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
|
|
||||||
def _has_reached_max_iterations(self) -> bool:
|
def _has_reached_max_iterations(self) -> bool:
|
||||||
"""Check if the maximum number of iterations has been reached."""
|
"""Check if the maximum number of iterations has been reached."""
|
||||||
print(f"Max iterations: {self.max_iter}")
|
|
||||||
print(f"Iterations: {self.iterations}")
|
|
||||||
return self.iterations >= self.max_iter
|
return self.iterations >= self.max_iter
|
||||||
|
|
||||||
def _enforce_rpm_limit(self) -> None:
|
def _enforce_rpm_limit(self) -> None:
|
||||||
@@ -218,7 +204,6 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
|
|||||||
content=f"Error during LLM call: {e}",
|
content=f"Error during LLM call: {e}",
|
||||||
color="red",
|
color="red",
|
||||||
)
|
)
|
||||||
# Re-raise the exception to let _invoke_loop handle it
|
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if not answer:
|
if not answer:
|
||||||
|
|||||||
Reference in New Issue
Block a user