#How long do I have to wait before sending a new api request?
5 messages · Page 1 of 1 (latest)
import openai
transcript = transcription
# Set up the OpenAI API key and model name
openai.api_key = "-"
# Split the transcript into chunks of 1000 words each
chunks = [transcript[i:i+1000] for i in range(0, len(transcript), 1000)]
# Initialize the accumulated response variable
response = ""
# Loop over each chunk and send it to the GPT-3 model
for chunk in chunks:
# Send the messages to the GPT-3 model and get the response
while True:
try:
chatproc = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": "format the following as flashcards in the format front1:back1\nfront2:back2\nfront3:back3\n for the following"},{"role": "user", "content": f'{chunk}'}])
chunk_response = chatproc.choices[0].message['content'].strip()
time.sleep(10)
break
except openai.error.APIError as e:
if e.status == 429: # Too Many Requests
retry_after = int(e.headers.get('Retry-After', '5'))
print(f"Rate limited. Retrying after {retry_after} seconds...")
time.sleep(retry_after)
else:
raise
# Add the response to the accumulated response variable
response += chunk_response
time.sleep(2)
# Print the final response
print(response)
transcript is a large transcript containing over 3000 words
how long do I have to wait before sending another api call?
10 seconds doesnt seem to be enough...