MetaGPT
MetaGPT copied to clipboard
Rate Limit Error (rate_limit_error) on anthropic 🪲
Bug description While it is running it reaches the Rate Limit (RPM) of the api, and seems to crash.
Environment information Linux codespaces-3fb395 6.2.0-1019-azure #19~22.04.1-Ubuntu SMP Wed Jan 10 22:57:03 UTC 2024 x86_64 GNU/Linux (Basic github codespace "2 core, 8Gb ram, 32GB")
- LLM type and model name: claude-3-haiku-20240307 of anthropic
- System version: 6.2.0-1019-azure 22.04.1-Ubuntu
- Python version: Python 3.11.4
- MetaGPT version or branch: main branch version 0.8.0
- installation method: Installed with the command
pip install -e .
Screenshots or logs
The `UI` class follows the design specified in the context, and it can be used by the `Game` class to update and display the game's UI elements.
2024-03-30 11:16:34.742 | WARNING | metagpt.utils.cost_manager:update_cost:49 - Model claude-3-haiku-20240307 not found in TOKEN_COSTS.
2024-03-30 11:16:34.743 | INFO | metagpt.actions.write_code_review:run:175 - Code review and rewrite ui.py: 1/2 | len(iterative_code)=1695, len(self.i_context.code_doc.content)=1695
2024-03-30 11:16:59.529 | WARNING | metagpt.utils.common:wrapper:649 - There is a exception in role's execution, in order to resume, we delete the newest role communication message in the role's memory.
2024-03-30 11:16:59.558 | ERROR | metagpt.utils.common:wrapper:631 - Exception occurs, start to serialize the project, exp:
Traceback (most recent call last):
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 50, in __call__
result = await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/actions/write_code_review.py", line 127, in write_code_review_and_rewrite
cr_rsp = await self._aask(context_prompt + cr_prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
anthropic.RateLimitError: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', 'message': 'Number of requests has exceeded your rate limit (https://docs.anthropic.com/claude/reference/rate-limits). Please try again later or contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.'}}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/workspaces/MetaGPT/metagpt/utils/common.py", line 640, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/role.py", line 550, in run
rsp = await self.react()
^^^^^^^^^^^^^^^^^^
tenacity.RetryError: RetryError[<Future at 0x7fda681c11d0 state=finished raised RateLimitError>]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/workspaces/MetaGPT/metagpt/utils/common.py", line 626, in wrapper
result = await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/team.py", line 134, in run
await self.env.run()
Exception: Traceback (most recent call last):
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 50, in __call__
result = await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/actions/write_code_review.py", line 127, in write_code_review_and_rewrite
cr_rsp = await self._aask(context_prompt + cr_prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/actions/action.py", line 93, in _aask
return await self.llm.aask(prompt, system_msgs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/provider/base_llm.py", line 150, in aask
rsp = await self.acompletion_text(message, stream=stream, timeout=self.get_timeout(timeout))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 88, in async_wrapped
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 47, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 314, in iter
return fut.result()
^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 50, in __call__
result = await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/provider/base_llm.py", line 200, in acompletion_text
return await self._achat_completion_stream(messages, timeout=self.get_timeout(timeout))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/provider/anthropic_api.py", line 54, in _achat_completion_stream
stream = await self.aclient.messages.create(**self._const_kwargs(messages, stream=True))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/resources/messages.py", line 1364, in create
return await self._post(
^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1728, in post
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1431, in request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1507, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1553, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1507, in _request
return await self._retry_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1553, in _retry_request
return await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/anthropic/_base_client.py", line 1522, in _request
raise self._make_status_error_from_response(err.response) from None
anthropic.RateLimitError: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', 'message': 'Number of requests has exceeded your rate limit (https://docs.anthropic.com/claude/reference/rate-limits). Please try again later or contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.'}}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/workspaces/MetaGPT/metagpt/utils/common.py", line 640, in wrapper
return await func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/role.py", line 550, in run
rsp = await self.react()
^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/role.py", line 517, in react
rsp = await self._react()
^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/role.py", line 463, in _react
rsp = await self._act()
^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/engineer.py", line 148, in _act
return await self._act_write_code()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/engineer.py", line 155, in _act_write_code
changed_files = await self._act_sp_with_cr(review=self.use_code_review)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/roles/engineer.py", line 116, in _act_sp_with_cr
coding_context = await action.run()
^^^^^^^^^^^^^^^^^^
File "/workspaces/MetaGPT/metagpt/actions/write_code_review.py", line 179, in run
result, rewrited_code = await self.write_code_review_and_rewrite(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 88, in async_wrapped
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/_asyncio.py", line 47, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/vscode/.local/lib/python3.11/site-packages/tenacity/__init__.py", line 326, in iter
raise retry_exc from fut.exception()
tenacity.RetryError: RetryError[<Future at 0x7fda681c11d0 state=finished raised RateLimitError>]
- Each provider has specific flow control by there own policy
- Now our logic has removed the RPM control logic, only the default retry
- Is it still not working after multiple retries?
Your API calls are too fast, and have been rate-limited:
anthropic.RateLimitError: Error code: 429 - {'type': 'error', 'error': {'type': 'rate_limit_error', 'message': 'Number of requests has exceeded your rate limit (https://docs.anthropic.com/claude/reference/rate-limits). Please try again later or contact sales at https://www.anthropic.com/contact-sales to discuss your options for a rate limit increase.'}}
@geekan
A little while ago I tried again with another prompt for another project, and it seems to have worked, in case it crashes again is there a command to resume where it stopped?
Can you take a look at the document https://docs.deepwisdom.ai/main/en/guide/in_depth_guides/breakpoint_recovery.html?
If you still have any questions, feel free to ask. I understand that this document does have some optimization points @better629