Skip to content

Commit 19baeb4

Browse files
committed
fix(codegen): backoff gemini rate limit
1 parent d834a22 commit 19baeb4

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

bigcodebench/model.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,24 @@ def codegen(
458458

459459
outputs = []
460460
for _ in range(batch_size):
461-
response = model.generate_content(
462-
"Please generate self-contained code to complete the following problem wrapped in a Python markdown block:"
463-
+ f"\n```python\n{prompt.strip()}\n```",
464-
generation_config=genai_config
465-
)
466-
try:
467-
output = response.candidates[0].content.parts[0].text
468-
outputs.append(output)
469-
except Exception as e:
470-
if "list index out of range" in str(e):
471-
# append dummy response
472-
outputs.append("NO_RESPONSE")
473-
else:
474-
raise e
461+
while True:
462+
try:
463+
response = model.generate_content(
464+
"Please generate self-contained code to complete the following problem wrapped in a Python markdown block:"
465+
+ f"\n```python\n{prompt.strip()}\n```",
466+
generation_config=genai_config
467+
)
468+
output = response.candidates[0].content.parts[0].text
469+
outputs.append(output)
470+
break
471+
except Exception as e:
472+
if "list index out of range" in str(e):
473+
# append dummy response
474+
outputs.append("NO_RESPONSE")
475+
break
476+
else:
477+
print(e)
478+
continue
475479

476480
return outputs
477481

0 commit comments

Comments
 (0)