feat: GPT Image 模型名映射及全局报错文案优化

- GPT Image 模型下拉选项映射为实际 API 参数(次卡→gpt-image-2-c,按量→gpt-image-2)
- 全局:含 "high load" 关键词的错误统一展示为"模型过载,请稍后重试!"
- GPT 独立:500 错误展示为"触发内容风控,或服务器繁忙!"

Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
o1key
2026-05-25 10:36:38 +08:00
co-authored by Claude Opus 4.7
parent 8eae3da298
commit 228c4c5141
4 changed files with 35 additions and 13 deletions
+3 -3
View File
@@ -14,7 +14,7 @@ import time
import aiohttp
from ..utils.http_error import HTTP_ERROR_MESSAGES, RETRYABLE_STATUS_CODES, _compute_delay, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY, DEFAULT_MAX_DELAY, DEFAULT_BACKOFF_FACTOR
from ..utils.http_error import HTTP_ERROR_MESSAGES, RETRYABLE_STATUS_CODES, _compute_delay, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY, DEFAULT_MAX_DELAY, DEFAULT_BACKOFF_FACTOR, get_friendly_message
@@ -276,13 +276,13 @@ class BaseAPIClient(ABC):
if status in HTTP_ERROR_MESSAGES:
raise RuntimeError(HTTP_ERROR_MESSAGES[status])
raise RuntimeError(error_text)
raise RuntimeError(get_friendly_message(status, error_text))
return result
if last_error_status and last_error_status in HTTP_ERROR_MESSAGES:
raise RuntimeError(HTTP_ERROR_MESSAGES[last_error_status])
raise RuntimeError(last_error_text)
raise RuntimeError(get_friendly_message(last_error_status or 0, last_error_text))
except InterruptProcessingException:
raise
+12 -3
View File
@@ -26,7 +26,12 @@ from PIL import Image
from ..utils.config import get_api_key_or_raise, get_api_base_url
from ..utils.image_utils import tensor_to_pil, encode_image_to_base64
from ..utils.http_error import RETRYABLE_STATUS_CODES, HTTP_ERROR_MESSAGES, _compute_delay, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY, DEFAULT_MAX_DELAY, DEFAULT_BACKOFF_FACTOR
from ..utils.http_error import RETRYABLE_STATUS_CODES, HTTP_ERROR_MESSAGES, _compute_delay, DEFAULT_MAX_RETRIES, DEFAULT_BASE_DELAY, DEFAULT_MAX_DELAY, DEFAULT_BACKOFF_FACTOR, get_friendly_message
# GPT Image 专属错误文案
_GPT_ERROR_MESSAGES = {
500: "触发内容风控,或服务器繁忙!",
}
try:
from comfy.model_management import processing_interrupted, InterruptProcessingException
@@ -346,6 +351,8 @@ class GptImageClient:
print(f"[o1key GPT Image] {friendly} {delay:.1f}s 后重试 ({attempt+1}/{DEFAULT_MAX_RETRIES})...")
await asyncio.sleep(delay)
continue
if resp.status in _GPT_ERROR_MESSAGES:
raise RuntimeError(_GPT_ERROR_MESSAGES[resp.status])
if resp.status in HTTP_ERROR_MESSAGES:
raise RuntimeError(HTTP_ERROR_MESSAGES[resp.status])
try:
@@ -358,7 +365,7 @@ class GptImageClient:
)
except Exception:
msg = text
raise RuntimeError(f"请求失败 HTTP {resp.status}: {msg}")
raise RuntimeError(get_friendly_message(resp.status, msg))
try:
resp_json = json.loads(text)
@@ -462,6 +469,8 @@ class GptImageClient:
text = await resp.text()
if resp.status != 200:
if resp.status in _GPT_ERROR_MESSAGES:
raise RuntimeError(_GPT_ERROR_MESSAGES[resp.status])
if resp.status in HTTP_ERROR_MESSAGES:
raise RuntimeError(HTTP_ERROR_MESSAGES[resp.status])
try:
@@ -474,7 +483,7 @@ class GptImageClient:
)
except Exception:
msg = text
raise RuntimeError(f"请求失败 HTTP {resp.status}: {msg}")
raise RuntimeError(get_friendly_message(resp.status, msg))
try:
resp_json = json.loads(text)