From d05afb2970e694bdfb20f2deb689c3cb035bd3d3 Mon Sep 17 00:00:00 2001 From: Nubenetes Bot Date: Thu, 21 May 2026 11:25:50 +0200 Subject: [PATCH] fix: adjust batch size to 50 and enforce strict Lite-only policy - Reduced BATCH_SIZE_FAST to 50 to prevent AI request timeouts. - Hardened call_gemini_with_retry to strictly use Flash/Lite models when prefer_flash=True. - Ensured newest model versions are prioritized within the Flash tier. --- src/gemini_utils.py | 8 ++++++-- src/v2_optimizer.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gemini_utils.py b/src/gemini_utils.py index ab640b18..3d6643fa 100644 --- a/src/gemini_utils.py +++ b/src/gemini_utils.py @@ -293,9 +293,13 @@ async def call_gemini_with_retry(prompt: str, response_format: str = "json", max consecutive_429s = 0 base_wait_time = 2.0 - # 1. Smart Re-ordering + # 1. Smart Filtering and Re-ordering (Strict Lite-Only Policy for Tier 1) if prefer_flash: - models = sorted(models_pool, key=lambda m: 0 if "flash" in m or "lite" in m else 1) + # Strict filter: Only allow flash/lite models, maintaining version sorting from pool + models = [m for m in models_pool if "flash" in m or "lite" in m] + if not models: + # Emergency fallback: if no flash/lite discovered, use hardcoded safe defaults + models = ["gemini-1.5-flash", "gemini-1.5-flash-latest"] else: models = models_pool diff --git a/src/v2_optimizer.py b/src/v2_optimizer.py index 3f249383..042ee648 100644 --- a/src/v2_optimizer.py +++ b/src/v2_optimizer.py @@ -319,7 +319,7 @@ class V2VisionEngine: analyst_results = [] # 1.1 Fast-Track: Large Batches, NO GROUNDING (Fast) - BATCH_SIZE_FAST = 100 # Increased from 40 for optimal RPM/TPM balance + BATCH_SIZE_FAST = 50 # Balanced "Sweet Spot" for RPM/TPM and timeout safety (2026) total_fast = len(fast_track) for i in range(0, total_fast, BATCH_SIZE_FAST): batch = fast_track[i:i+BATCH_SIZE_FAST]