Skip to content
Open
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
17 changes: 15 additions & 2 deletions camel/agents/chat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
)
from pydantic import BaseModel, ValidationError

try:
from anthropic import RateLimitError as AnthropicRateLimitError
except ImportError:
AnthropicRateLimitError = None # type: ignore[misc,assignment]
Comment on lines +59 to +62
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to add anthropic as required dependency to make sure this function would work


# Tuple of all rate limit errors to catch during retry logic.
# OpenAI and Anthropic have separate RateLimitError classes.
_RATE_LIMIT_ERRORS: tuple = (
(RateLimitError, AnthropicRateLimitError)
if AnthropicRateLimitError is not None
else (RateLimitError,)
)

from camel.agents._types import ModelResponse, ToolCallRequest
from camel.agents._utils import (
build_default_summary_prompt,
Expand Down Expand Up @@ -3592,7 +3605,7 @@ def _get_model_response(
)
if response:
break
except RateLimitError as e:
except _RATE_LIMIT_ERRORS as e:
last_error = e
if attempt < self.retry_attempts - 1:
delay = min(self.retry_delay * (2**attempt), 60.0)
Expand Down Expand Up @@ -3654,7 +3667,7 @@ async def _aget_model_response(
)
if response:
break
except RateLimitError as e:
except _RATE_LIMIT_ERRORS as e:
last_error = e
if attempt < self.retry_attempts - 1:
delay = min(self.retry_delay * (2**attempt), 60.0)
Expand Down
Loading