Richard Fan commited on
Commit
486f1fd
·
1 Parent(s): 9910188

remove ratelimiter infinite loop

Browse files
Files changed (1) hide show
  1. src/utils.py +7 -1
src/utils.py CHANGED
@@ -96,6 +96,8 @@ def openai_completion(
96
  ):
97
  batch_decoding_args = copy.deepcopy(decoding_args) # cloning the decoding_args
98
 
 
 
99
  while True:
100
  try:
101
  shared_kwargs = dict(
@@ -115,7 +117,7 @@ def openai_completion(
115
  completion_batch = openai.Completion.create(prompt=prompt_batch, **shared_kwargs)
116
 
117
  choices = completion_batch.choices
118
-
119
  for choice in choices:
120
  choice["total_tokens"] = completion_batch.usage.total_tokens
121
  completions.extend(choices)
@@ -125,7 +127,11 @@ def openai_completion(
125
  if "Please reduce your prompt" in str(e):
126
  batch_decoding_args.max_tokens = int(batch_decoding_args.max_tokens * 0.8)
127
  logging.warning(f"Reducing target length to {batch_decoding_args.max_tokens}, Retrying...")
 
 
 
128
  else:
 
129
  logging.warning("Hit request rate limit; retrying...")
130
  time.sleep(sleep_time) # Annoying rate limit on requests.
131
 
 
96
  ):
97
  batch_decoding_args = copy.deepcopy(decoding_args) # cloning the decoding_args
98
 
99
+ backoff = 3
100
+
101
  while True:
102
  try:
103
  shared_kwargs = dict(
 
117
  completion_batch = openai.Completion.create(prompt=prompt_batch, **shared_kwargs)
118
 
119
  choices = completion_batch.choices
120
+
121
  for choice in choices:
122
  choice["total_tokens"] = completion_batch.usage.total_tokens
123
  completions.extend(choices)
 
127
  if "Please reduce your prompt" in str(e):
128
  batch_decoding_args.max_tokens = int(batch_decoding_args.max_tokens * 0.8)
129
  logging.warning(f"Reducing target length to {batch_decoding_args.max_tokens}, Retrying...")
130
+ elif not backoff:
131
+ logging.error("Hit too many failures, exiting")
132
+ raise e
133
  else:
134
+ backoff -= 1
135
  logging.warning("Hit request rate limit; retrying...")
136
  time.sleep(sleep_time) # Annoying rate limit on requests.
137