Rate Limit Error

on running the prompt i got rate limit error.

I’m also getting same error. Are you able to fix this?

Can you please give some advice to understand and avoid Rate Limit Errors?

The rate limit error occurs because ChatGPT has a limit of responses by minute (3 by minute), so in order to fix it you need to paid for the “no limit version” or, as i fixed:
“import time” in your code
then each time you need a response add a
“time.sleep(20)” where 20 is the time in second you will wait before asking ia to bring a response.
this way, yes, you get a little bored waiting but you don´t have to execute example by example or pay nothing.

Example:

import openai
import os
import time

from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())

openai.api_key = "APIKEY"


def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=0,  # this is the degree of randomness of the model's output
    )
    return response.choices[0].message["content"]


prompt = f"""
Translate the following English text to Spanish: \ 
```Hi, I would like to order a blender```
"""

response = get_completion(prompt)
print(response)

prompt = f"""
Tell me which language this is: 
```Combien coûte le lampadaire?```
"""
time.sleep(20)
response = get_completion(prompt)
print(response)

prompt = f"""
Translate the following  text to French and Spanish
and English pirate: \
```I want to order a basketball```
"""
time.sleep(20)
response = get_completion(prompt)
print(response)

prompt = f"""
Translate the following text to Spanish in both the \
formal and informal forms: 
'Would you like to order a pillow?'
"""
time.sleep(20)
response = get_completion(prompt)
print(response)
1 Like