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