mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 08:01:07 +00:00
Merge pull request #45 from lijirou12/codex/migrate-imagine-to-grok-superimage-1.0-pg7sej
Add grok-superimage model with server-side image config, improve SSE error handling and transient retry logic
This commit is contained in:
4 files changed
+59
-7
No files matched your search
@@ -22,7 +22,7 @@ from app.core.exceptions import (
|
||||
from app.services.grok.services.model import ModelService
|
||||
from app.services.grok.utils.upload import UploadService
|
||||
from app.services.grok.utils import process as proc_base
|
||||
from app.services.grok.utils.retry import pick_token, rate_limited
|
||||
from app.services.grok.utils.retry import pick_token, rate_limited, transient_upstream
|
||||
from app.services.reverse.app_chat import AppChatReverse
|
||||
from app.services.reverse.utils.session import ResettableSession
|
||||
from app.services.grok.utils.stream import wrap_stream_with_usage
|
||||
@@ -481,6 +481,13 @@ class ChatService:
|
||||
)
|
||||
continue
|
||||
|
||||
if transient_upstream(e):
|
||||
logger.warning(
|
||||
f"Transient upstream error for token {token[:10]}..., "
|
||||
f"trying next token (attempt {attempt + 1}/{max_token_retries}): {e}"
|
||||
)
|
||||
continue
|
||||
|
||||
# 非 429 错误,不换 token,直接抛出
|
||||
raise
|
||||
|
||||
|
||||
@@ -42,4 +42,24 @@ def rate_limited(error: Exception) -> bool:
|
||||
return status == 429 or code == "rate_limit_exceeded"
|
||||
|
||||
|
||||
__all__ = ["pick_token", "rate_limited"]
|
||||
def transient_upstream(error: Exception) -> bool:
|
||||
"""Whether error is likely transient and safe to retry with another token."""
|
||||
if not isinstance(error, UpstreamException):
|
||||
return False
|
||||
details = error.details or {}
|
||||
status = details.get("status")
|
||||
err = str(details.get("error") or error).lower()
|
||||
transient_status = {408, 500, 502, 503, 504}
|
||||
if status in transient_status:
|
||||
return True
|
||||
timeout_markers = (
|
||||
"timed out",
|
||||
"timeout",
|
||||
"connection reset",
|
||||
"temporarily unavailable",
|
||||
"http2",
|
||||
)
|
||||
return any(marker in err for marker in timeout_markers)
|
||||
|
||||
|
||||
__all__ = ["pick_token", "rate_limited", "transient_upstream"]
|
||||
@@ -123,11 +123,12 @@ class AppChatReverse:
|
||||
)
|
||||
|
||||
# Curl Config
|
||||
timeout = max(
|
||||
float(get_config("chat.timeout") or 0),
|
||||
float(get_config("video.timeout") or 0),
|
||||
float(get_config("image.timeout") or 0),
|
||||
)
|
||||
timeout = float(get_config("chat.timeout") or 0)
|
||||
if timeout <= 0:
|
||||
timeout = max(
|
||||
float(get_config("video.timeout") or 0),
|
||||
float(get_config("image.timeout") or 0),
|
||||
)
|
||||
browser = get_config("proxy.browser")
|
||||
|
||||
async def _do_request():
|
||||
|
||||
@@ -100,6 +100,14 @@ const LOCALE_MAP = {
|
||||
},
|
||||
|
||||
|
||||
"superimage": {
|
||||
"label": "SuperImage 配置",
|
||||
"n": { title: "生成数量", desc: "仅用于 grok-superimage-1.0 的服务端统一生成数量(1-10)。" },
|
||||
"size": { title: "图片尺寸", desc: "仅用于 grok-superimage-1.0 的服务端统一尺寸。" },
|
||||
"response_format": { title: "响应格式", desc: "仅用于 grok-superimage-1.0 的服务端统一返回格式。" }
|
||||
},
|
||||
|
||||
|
||||
"asset": {
|
||||
"label": "资产配置",
|
||||
"upload_concurrent": { title: "上传并发", desc: "上传接口的最大并发数。推荐 30。" },
|
||||
@@ -412,6 +420,22 @@ function buildFieldCard(section, key, val) {
|
||||
{ val: 'url', text: 'URL' }
|
||||
]);
|
||||
}
|
||||
else if (section === 'superimage' && key === 'size') {
|
||||
built = buildSelectInput(section, key, val, [
|
||||
{ val: '1024x1024', text: '1024x1024 (1:1)' },
|
||||
{ val: '1280x720', text: '1280x720 (16:9)' },
|
||||
{ val: '720x1280', text: '720x1280 (9:16)' },
|
||||
{ val: '1792x1024', text: '1792x1024 (3:2)' },
|
||||
{ val: '1024x1792', text: '1024x1792 (2:3)' }
|
||||
]);
|
||||
}
|
||||
else if (section === 'superimage' && key === 'response_format') {
|
||||
built = buildSelectInput(section, key, val, [
|
||||
{ val: 'url', text: 'URL' },
|
||||
{ val: 'b64_json', text: 'B64 JSON' },
|
||||
{ val: 'base64', text: 'Base64' }
|
||||
]);
|
||||
}
|
||||
else if (Array.isArray(val) || typeof val === 'object') {
|
||||
built = buildJsonInput(section, key, val);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user