返回提交历史
Modified
g4f/Provider/needs_auth/Antigravity.py
+3
-2
Modified
g4f/Provider/needs_auth/GeminiCLI.py
+1
-1
Modified
g4f/api/__init__.py
+4
-0
XFEstudio/gpt4free
fix: enhance error handling for RateLimitError and update tool call ID assignment
c7d231a3
代码差异
3 个文件
+8
-3
@@ -1237,7 +1237,8 @@ class AntigravityProvider:
1237
1237
elif resp.status == 429:
1238
1238
try:
1239
1239
message = (await resp.json()).get("error", {}).get("message", "")
1240
except Exception:
1240
except Exception as e:
1241
debug.error("Error parsing error message:", e)
1241
1242
message = await resp.text()
1242
1243
raise RateLimitError(f"Error 429: {message}")
1243
1244
raise RuntimeError(f"Antigravity API error {resp.status}: {await resp.text()}")
@@ -1286,7 +1287,7 @@ class AntigravityProvider:
1286
1287
for i, part in enumerate(tool_calls):
1287
1288
tc = part["functionCall"]
1288
1289
tool_call_obj = {
1289
"id": f"call_{i}_{tc.get('name', 'unknown')}",
1290
"id": tc.get("id", f"call_{i}_{tc.get('name', 'unknown')}"),
1290
1291
"type": "function",
1291
1292
"function": {
1292
1293
"name": tc.get("name"),
@@ -854,7 +854,7 @@ class GeminiCLIProvider():
854
854
for i, part in enumerate(tool_calls):
855
855
tc = part["functionCall"]
856
856
tool_call_obj = {
857
"id": f"call_{i}_{tc.get('name', 'unknown')}",
857
"id": tc.get("id", f"call_{i}_{tc.get('name', 'unknown')}"),
858
858
"type": "function",
859
859
"function": {
860
860
"name": tc.get("name"),
@@ -451,6 +451,7 @@ class Api:
451
451
HTTP_401_UNAUTHORIZED: {"model": ErrorResponseModel},
452
452
HTTP_404_NOT_FOUND: {"model": ErrorResponseModel},
453
453
HTTP_422_UNPROCESSABLE_ENTITY: {"model": ErrorResponseModel},
454
HTTP_429_TOO_MANY_REQUESTS: {"model": ErrorResponseModel},
454
455
HTTP_500_INTERNAL_SERVER_ERROR: {"model": ErrorResponseModel},
455
456
}
456
457
@self.app.post("/v1/chat/completions", responses=responses)
@@ -555,6 +556,8 @@ class Api:
555
556
except (MissingAuthError, NoValidHarFileError) as e:
556
557
logger.exception(e)
557
558
return ErrorResponse.from_exception(e, config, HTTP_401_UNAUTHORIZED)
559
except RateLimitError as e:
560
return ErrorResponse.from_exception(e, config, HTTP_429_TOO_MANY_REQUESTS)
558
561
except Exception as e:
559
562
logger.exception(e)
560
563
return ErrorResponse.from_exception(e, config, HTTP_500_INTERNAL_SERVER_ERROR)
@@ -563,6 +566,7 @@ class Api:
563
566
HTTP_200_OK: {"model": ImagesResponse},
564
567
HTTP_401_UNAUTHORIZED: {"model": ErrorResponseModel},
565
568
HTTP_404_NOT_FOUND: {"model": ErrorResponseModel},
569
HTTP_429_TOO_MANY_REQUESTS: {"model": ErrorResponseModel},
566
570
HTTP_500_INTERNAL_SERVER_ERROR: {"model": ErrorResponseModel},
567
571
}
568
572
@self.app.post("/v1/media/generate", responses=responses)