feat: support Grok platform account imports
This commit is contained in:
@@ -593,14 +593,24 @@ def import_groups_from_upstream(
|
||||
)
|
||||
|
||||
|
||||
SUPPORTED_PLATFORMS = {"openai", "anthropic", "gemini", "antigravity"}
|
||||
def _normalize_platform(platform: str) -> str:
|
||||
"""统一平台值:小写、xai → grok。"""
|
||||
p = platform.lower().strip()
|
||||
if p == "xai":
|
||||
return "grok"
|
||||
return p
|
||||
|
||||
|
||||
SUPPORTED_PLATFORMS = {"openai", "anthropic", "gemini", "grok", "antigravity"}
|
||||
|
||||
|
||||
def _resolve_platform(text: str, group_snapshot: dict | None, fallback: str = "openai") -> str:
|
||||
if group_snapshot and isinstance(group_snapshot, dict):
|
||||
platform = group_snapshot.get("platform")
|
||||
if platform and str(platform).lower() in SUPPORTED_PLATFORMS:
|
||||
return str(platform).lower()
|
||||
raw = group_snapshot.get("platform")
|
||||
if raw:
|
||||
platform = _normalize_platform(str(raw))
|
||||
if platform in SUPPORTED_PLATFORMS:
|
||||
return platform
|
||||
return _detect_platform(text, fallback)
|
||||
|
||||
|
||||
@@ -611,9 +621,11 @@ def _detect_platform(text: str, fallback: str = "openai") -> str:
|
||||
return "anthropic"
|
||||
if "gemini" in lower:
|
||||
return "gemini"
|
||||
if "grok" in lower or "xai" in lower:
|
||||
return "grok"
|
||||
if "antigravity" in lower:
|
||||
return "antigravity"
|
||||
return fallback
|
||||
return _normalize_platform(fallback)
|
||||
|
||||
|
||||
@router.post("/api/websites/{wid}/accounts/sync-imported-upstream-keys", response_model=ImportAccountsResponse)
|
||||
@@ -869,7 +881,7 @@ def import_upstream_keys_as_accounts(
|
||||
body.default_platform,
|
||||
)
|
||||
else:
|
||||
platform = body.default_platform
|
||||
platform = _normalize_platform(body.default_platform)
|
||||
|
||||
upstream = upstreams_map.get(row.upstream_id)
|
||||
upstream_name = upstream.name if upstream else "Unknown"
|
||||
|
||||
Reference in New Issue
Block a user