移除 NanoBananaPro 单张模式的自动重试逻辑

This commit is contained in:
o1key
2026-04-27 12:25:58 +08:00
parent c646b0d1d7
commit 85f9228220
+15 -32
View File
@@ -686,38 +686,21 @@ class NanoBananaPro:
else: else:
# 单提示词模式 # 单提示词模式
if 生图数量 == 1: if 生图数量 == 1:
# 单张:同步生成,自动重试(429/503/504 # 单张:同步生成
_RETRY_CODES = ("429", "503", "504") generated_images = self.client.generate_sync(
_MAX_RETRIES = 5 prompt=prompt,
for _attempt in range(1, _MAX_RETRIES + 1): model=模型,
try: resolution=分辨率,
generated_images = self.client.generate_sync( aspect_ratio=宽高比,
prompt=prompt, batch_size=1,
model=模型, images=input_images,
resolution=分辨率, progress_callback=progress_callback,
aspect_ratio=宽高比, debug=DEBUG_LOG_ENABLED,
batch_size=1, debug_request=REQUEST_LOG_ENABLED,
images=input_images, enable_grounding=enable_grounding,
progress_callback=progress_callback, enable_image_search=enable_image_search,
debug=DEBUG_LOG_ENABLED, image_format=image_format,
debug_request=REQUEST_LOG_ENABLED, )
enable_grounding=enable_grounding,
enable_image_search=enable_image_search,
image_format=image_format,
)
break
except RuntimeError as e:
error_msg = str(e)
if any(code in error_msg for code in _RETRY_CODES) and _attempt < _MAX_RETRIES:
_wait = 2 ** _attempt
print(f"{'=' * 60}")
print(f"⚠️ Nano Banana Pro 自动重试 [{_attempt}/{_MAX_RETRIES - 1}]")
print(f" 原因:{error_msg}")
print(f" 等待 {_wait}s 后重试...")
print(f"{'=' * 60}")
time.sleep(_wait)
else:
raise
else: else:
# 多张:异步并发,内存输出 # 多张:异步并发,内存输出