ChatDev icon indicating copy to clipboard operation
ChatDev copied to clipboard

Rate limit.

Open loprx opened this issue 3 years ago • 29 comments

Recommend adding current limiting function.

This is error.

openai.error.RateLimitError: Rate limit reached for 10KTPM-200RPM in organization org-xxxxxxx on tokens per min. Limit: 10000 / min. Please try again in 6ms. Contact us through our help center at help.openai.com if you continue to have issues.

rate limit refer to https://github.com/geekan/MetaGPT/blob/main/metagpt/provider/openai_api.py

loprx avatar Sep 08 '23 07:09 loprx

Thank you. We will check it out. By the way, in our test we haven't met this rate limit error, is it because some kinds of batch running in your scenario?

thinkwee avatar Sep 08 '23 10:09 thinkwee

I am hitting the rate limit error too. I was using my GPT_4 API key. I tried the 32K version and got a different error. No batch script, just running from from inside VsCode terminal/windows 11.
"python run.py --task "write a me this example program" --name "Example Name" --model 'GPT_4'

Tracebacks below.

GPT 4 Traceback

[OpenAI_Usage_Info Receive] prompt_tokens: 453 completion_tokens: 74 total_tokens: 527

Traceback (most recent call last): File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\tenacity_init_.py", line 382, in call result = fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\ChatDev\camel\utils.py", line 145, in wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\ChatDev\camel\agents\chat_agent.py", line 191, in step response = self.model_backend.run(messages=openai_messages) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\ChatDev\camel\model_backend.py", line 69, in run response = openai.ChatCompletion.create(*args, **kwargs, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create return super().create(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( ^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_requestor.py", line 298, in request resp, got_stream = self._interpret_response(result, stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_requestor.py", line 700, in _interpret_response self._interpret_response_line( File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_requestor.py", line 763, in _interpret_response_line raise self.handle_error_response( openai.error.RateLimitError: Rate limit reached for 10KTPM-200RPM in organization org-PcnGPHPM8C05nx9hV0x7Wie6 on tokens per min. Limit: 10000 / min. Please try again in 6ms. Contact us through our help center at help.openai.com if you continue to have issues.

GPT4 32K TRACEBACK

"python run.py --task "write a me this example program" --name "Example Name" --model 'GPT_4_32K'

Traceback (most recent call last): File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\tenacity_init_.py", line 382, in call result = fn(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\ChatDev\camel\utils.py", line 145, in wrapper return func(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\ChatDev\camel\agents\chat_agent.py", line 191, in step response = self.model_backend.run(messages=openai_messages) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\ChatDev\camel\model_backend.py", line 69, in run response = openai.ChatCompletion.create(*args, **kwargs, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_resources\chat_completion.py", line 25, in create return super().create(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_resources\abstract\engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( ^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_requestor.py", line 298, in request resp, got_stream = self._interpret_response(result, stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_requestor.py", line 700, in _interpret_response self._interpret_response_line( File "H:\PROGRAMS\chatdev\venv\Lib\site-packages\openai\api_requestor.py", line 763, in _interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: The model gpt-4-32k does not exist or you do not have access to it. Learn more: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4.

IIEleven11 avatar Sep 09 '23 04:09 IIEleven11

refer to this page for rate limits https://platform.openai.com/account/rate-limits

hemangjoshi37a avatar Sep 09 '23 08:09 hemangjoshi37a

Thank you. We will check it out.

By the way, in our test we haven't met this rate limit error, is it because some kinds of batch running in your scenario?

As they said, this problem occurs when using the GPT4 model.

loprx avatar Sep 09 '23 13:09 loprx

refer to this page for rate limits https://platform.openai.com/account/rate-limits

Is this a joke? I understand what rate limits are. I am trying to use Open Interpreter with a gpt4 api key and I cannot because there is no functionality that allows for waiting the required amount of time and or working around the limit in some other way.

IIEleven11 avatar Sep 09 '23 16:09 IIEleven11

FORK THE Repo

Change the code to use v2 completion endpoint May fix the issue

Nbtguyoriginal avatar Sep 10 '23 04:09 Nbtguyoriginal

I get the same error. Works fine with GPT3.5 but if I try GPT4 it crashes to: openai.error.RateLimitError: Rate limit reached for 10KTPM-200RPM

Storhemulen avatar Sep 12 '23 20:09 Storhemulen

I get the same error. Works fine with GPT3.5 but if I try GPT4 it crashes to: openai.error.RateLimitError: Rate limit reached for 10KTPM-200RPM image

wghuang-aigc avatar Sep 14 '23 07:09 wghuang-aigc

I followed the example using Tenacity here, and I was able to limit the requests made to the GPT-4 endpoints. I'll need to dial in the variables, but it works out the gate without any modifications. https://platform.openai.com/docs/guides/rate-limits/error-mitigation

fasterinnerlooper avatar Sep 17 '23 22:09 fasterinnerlooper

also experiencing this issue using GPT4. is there somewhere in the code where i can add a rate limit or adjust how requests are sent to the API so that i can run this and ensure rate limit isn't reached so my project can complete? i prefer to use GPT4 because 1. i have access and 2. it seems to perform better, particularly with coding, from my experience.

tbels89 avatar Sep 19 '23 21:09 tbels89

also experiencing this issue using GPT4. is there somewhere in the code where i can add a rate limit or adjust how requests are sent to the API so that i can run this and ensure rate limit isn't reached so my project can complete? i prefer to use GPT4 because 1. i have access and 2. it seems to perform better, particularly with coding, from my experience.

Hi @tbels89, If you follow the link in my comment above, you can see an example that uses the Tenacity library. The examples that are there need to be tweaked because it backs off quite aggressively, but it was working well for me.

fasterinnerlooper avatar Sep 20 '23 02:09 fasterinnerlooper

Hi @tbels89, If you follow the link in my comment above, you can see an example that uses the Tenacity library. The examples that are there need to be tweaked because it backs off quite aggressively, but it was working well for me.

@sjetha i had a look but i'm not sure where in the program to put the tenacity. what file(s) did you modify to get this working? can you show an example of your implementation? i'm still pretty new to this and trying to figure it all out.

tbels89 avatar Sep 20 '23 13:09 tbels89

Can some one show an example code or tell how to fix it?

karingijs2727 avatar Sep 21 '23 14:09 karingijs2727

Can some one show an example code or tell how to fix it?

You can add sleep code in the request openai API.

loprx avatar Sep 21 '23 15:09 loprx

@sjetha thanks for the tenacity suggestion. i was able to implement and using gpt4. i reviewed the log and it did have some rate limit hits, but because of the retry, never killed the process and chatdev was able to complete the task (not exactly what i was hoping it would output, but at least not hitting rate limits). for everyone wondering, here's what i did:

file: chatdev-main/camel/model_backend.py

import: from tenacity import retry, wait_exponential

under the OpenAIModel class, just above the run function, i added the following line of code: @retry(wait=wait_exponential(multiplier=0.02, max=20))

tbels89 avatar Sep 21 '23 17:09 tbels89

Why has this been closed? it never works for me - always errors for GPT 4 - I fought hard to get access :)

sakher avatar Sep 22 '23 10:09 sakher

Why has this been closed? it never works for me - always errors for GPT 4 - I fought hard to get access :)

quote your api_key in your code

wghuang-aigc avatar Sep 25 '23 09:09 wghuang-aigc

Like @sakher mentioned, add his code and mess with variables. I added:

@retry(wait=wait_exponential(min=1, max=60)) above the OpenAIModel class and my issues were fixed (using 3.5 turbo)

sebib96 avatar Sep 26 '23 23:09 sebib96

Still facing rate limit error with GPT-4. Any confirmed fix?

GBurgardt avatar Sep 27 '23 01:09 GBurgardt

For those doing a direct copy and paste of @tbels89 suggested modification, I believe the 'R' in @Retry should be lower case, i.e., @retry(...)

Edit: comments automatically capitalise the letter following '@' so '@ retry(...)' without space

flipflop4 avatar Sep 27 '23 15:09 flipflop4