From 761696f4c6d0e6c9c37516bdb047b7129f7647cf Mon Sep 17 00:00:00 2001 From: Pu Fanyi Date: Tue, 7 Jan 2025 13:59:31 +0800 Subject: [PATCH] Fix retry logic in GeminiAPI by adjusting attempt count and initializing content variable --- lmms_eval/models/gemini_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lmms_eval/models/gemini_api.py b/lmms_eval/models/gemini_api.py index 65718bc55..72892e7e0 100644 --- a/lmms_eval/models/gemini_api.py +++ b/lmms_eval/models/gemini_api.py @@ -149,6 +149,8 @@ def get_uuid(task, split, doc_id): message = [contexts] + visuals + content = "" + for attempt in range(5): try: content = self.model.generate_content( @@ -172,7 +174,7 @@ def get_uuid(task, split, doc_id): break except Exception: pass - if attempt < 5 - 1: # If we have retries left, sleep and then continue to next attempt + if attempt < 4 - 1: # If we have retries left, sleep and then continue to next attempt time.sleep(NUM_SECONDS_TO_SLEEP) else: # If this was the last attempt, log and return empty eval_logger.error(f"All 5 attempts failed. Last error message: {str(e)}")