feat: 错误提示中文化、GPT Image 余额查询、Nano Banana 自动重试
- gemini_client: 更新 429/504 中文错误文案,与产品文案对齐 - gpt_image_client: 新增 query_balance_sync / format_balance_info 余额查询方法 - gpt_image: 每次执行后打印余额日志(finally 块保证触发) - nano_banana_pro: 单张生成支持自动重试,遇 429/503/504 最多重试 4 次,指数退避 2-32s,终端显示显眼重试状态 - nano_banana_pro: 关闭调试日志(DEBUG_LOG_ENABLED = False) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 4.5
parent
949f7bb180
commit
fe3cc65b71
+32
-15
@@ -52,7 +52,7 @@ except ImportError:
|
||||
# ============================================================================
|
||||
# 是否启用调试日志(打印完整的 API 响应内容)
|
||||
# 设置为 True 以启用调试日志,False 以禁用
|
||||
DEBUG_LOG_ENABLED = True
|
||||
DEBUG_LOG_ENABLED = False
|
||||
# 是否启用请求体日志(打印发送给 API 的请求体,base64 图片数据将自动截断)
|
||||
# 设置为 True 以启用请求体日志,False 以禁用
|
||||
REQUEST_LOG_ENABLED = False
|
||||
@@ -665,20 +665,37 @@ class NanoBananaPro:
|
||||
else:
|
||||
# 单提示词模式
|
||||
if 生图数量 == 1:
|
||||
# 单张:同步生成,输出 tensor
|
||||
generated_images = self.client.generate_sync(
|
||||
prompt=prompt,
|
||||
model=模型,
|
||||
resolution=分辨率,
|
||||
aspect_ratio=宽高比,
|
||||
batch_size=1,
|
||||
images=input_images,
|
||||
progress_callback=progress_callback,
|
||||
debug=DEBUG_LOG_ENABLED,
|
||||
debug_request=REQUEST_LOG_ENABLED,
|
||||
enable_grounding=enable_grounding,
|
||||
enable_image_search=enable_image_search,
|
||||
)
|
||||
# 单张:同步生成,自动重试(429/503/504)
|
||||
_RETRY_CODES = ("429", "503", "504")
|
||||
_MAX_RETRIES = 5
|
||||
for _attempt in range(1, _MAX_RETRIES + 1):
|
||||
try:
|
||||
generated_images = self.client.generate_sync(
|
||||
prompt=prompt,
|
||||
model=模型,
|
||||
resolution=分辨率,
|
||||
aspect_ratio=宽高比,
|
||||
batch_size=1,
|
||||
images=input_images,
|
||||
progress_callback=progress_callback,
|
||||
debug=DEBUG_LOG_ENABLED,
|
||||
debug_request=REQUEST_LOG_ENABLED,
|
||||
enable_grounding=enable_grounding,
|
||||
enable_image_search=enable_image_search,
|
||||
)
|
||||
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:
|
||||
# 多张:异步并发,内存输出
|
||||
|
||||
|
||||
Reference in New Issue
Block a user