XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Refactor Antigravity quota fetching to streamline API usage and remove unnecessary grouping logic

affe0a0d
hlohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +2 -35
Modified g4f/Provider/needs_auth/Antigravity.py +2 -35
@@ -1350,8 +1350,7 @@ class Antigravity(AsyncGeneratorProvider, ProviderModelMixin):
1350 1350 @classmethod
1351 1351 async def get_quota(cls, api_key: Optional[str] = None) -> dict:
1352 1352 """
1353 Fetch and summarize quota usage for Antigravity account.
1354 Returns a dict with OpenAI Usage keys if possible, or quota info.
1353 Fetch usage/quota information from the Antigravity API.
1355 1354 """
1356 1355 if cls.auth_manager is None:
1357 1356 cls.auth_manager = AntigravityAuthManager(env=os.environ)
@@ -1362,43 +1361,11 @@ class Antigravity(AsyncGeneratorProvider, ProviderModelMixin):
1362 1361 if not access_token or not project_id:
1363 1362 raise MissingAuthError("Cannot fetch usage without valid authentication")
1364 1363
1365 data = await cls.auth_manager.call_endpoint(
1364 return await cls.auth_manager.call_endpoint(
1366 1365 method="fetchAvailableModels",
1367 1366 body={"project": cls.auth_manager.get_project_id()}
1368 1367 )
1369 1368
1370 def classify_group(model_name, display_name=None):
1371 combined = f"{model_name} {display_name or ''}".lower()
1372 if "claude" in combined:
1373 return "claude"
1374 if "gemini-3" in combined or "gemini 3" in combined:
1375 if "flash" in combined:
1376 return "gemini-flash"
1377 return "gemini-pro"
1378 if "gemini-2.5" in combined or "gemini 2.5" in combined:
1379 if "flash" in combined:
1380 return "gemini-flash"
1381 return "gemini-pro"
1382 return None
1383
1384 groups = {}
1385 models = data.get("models", {})
1386 for model_name, entry in models.items():
1387 group = classify_group(model_name, entry.get("displayName") or entry.get("modelName"))
1388 if not group:
1389 continue
1390 quota_info = entry.get("quotaInfo", {})
1391 remaining = quota_info.get("remainingFraction")
1392 reset_time = quota_info.get("resetTime")
1393 if group not in groups:
1394 groups[group] = {"remainingFraction": remaining, "resetTime": reset_time, "modelCount": 1}
1395 else:
1396 g = groups[group]
1397 g["remainingFraction"] = min(g["remainingFraction"], remaining) if g["remainingFraction"] is not None and remaining is not None else g["remainingFraction"] or remaining
1398 g["resetTime"] = reset_time if not g["resetTime"] or (reset_time and reset_time < g["resetTime"]) else g["resetTime"]
1399 g["modelCount"] += 1
1400 return {**data, "groups": groups}
1401
1402 1369 @classmethod
1403 1370 async def create_async_generator(
1404 1371 cls,