Hello community,
This time I want to use the openai api to perform translation task for 10000 sentences.
I understand that the scope fo the input might reach the rpm so I divided the 10000 sentences into 1000 groups, each of them contain 10 sentences instead.
n = 10
groups = [df[i:i+n] for i in range(0, len(df), n)]
# List to store the results
translated_groups = []
and I use the tranlsation model like following:
def translate_text(text):
prompt = f"Translate to English: \n\n{text}"
try:
response = client.completions.create(model="text-davinci-003",
prompt=prompt,
max_tokens=1024)
return response.choices[0].text.strip()
except Exception as e:
print(f"Error in translation: {e}")
# Implement a retry mechanism with a wait
if 'rate_limit_exceeded' in str(e):
print("Waiting for 20 seconds due to rate limit...")
time.sleep(20)
return translate_text(text) # Retry the translation
return ""
while I start executing this script, it still offer me error messages like this:
Error in translation: Error code: 429 - {âerrorâ: {âmessageâ: âRate limit reached for text-davinci-003 in organization org-ks1Km80tXvRB8z48mIM72sYC on requests per min (RPM): Limit 3, Used 3, Requested 1. Please try again in 20s. Visit https://platform.openai.com/account/rate-limits to learn more. You can increase your rate limit by adding a payment method to your account at https://platform.openai.com/account/billing.â, âtypeâ: ârequestsâ, âparamâ: None, âcodeâ: ârate_limit_exceededâ}}
I want to know that is there any solutions to fix this? or shall I could just pay for increasing the limitations.
Thank you.