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

XFEstudio/gpt4free

Refactor Antigravity and GeminiCLI providers to conditionally include allowedFunctionNames in toolConfig; improve error handling in Copilot provider for element selection

4961f091
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

4 个文件 +29 -17
Modified g4f/Provider/Copilot.py +12 -3
@@ -363,16 +363,25 @@ async def get_access_token_and_cookies(url: str, proxy: str = None, needs_auth:
363 363 debug.log("No access token found, but authentication not required.")
364 364 break
365 365 if not needs_auth:
366 textarea = await page.select("textarea")
366 try:
367 textarea = await page.select("textarea")
368 except TimeoutError:
369 textarea = None
367 370 if textarea is not None:
368 371 debug.log("Filling textarea to generate anon cookie.")
369 372 await textarea.send_keys("Hello")
370 373 await asyncio.sleep(1)
371 button = await page.select("[data-testid=\"submit-button\"]")
374 try:
375 button = await page.select("[data-testid=\"submit-button\"]")
376 except TimeoutError:
377 button = None
372 378 if button:
373 379 debug.log("Clicking submit button to generate anon cookie.")
374 380 await button.click()
375 turnstile = await page.select('#cf-turnstile')
381 try:
382 turnstile = await page.select('#cf-turnstile')
383 except TimeoutError:
384 turnstile = None
376 385 if turnstile:
377 386 debug.log("Found Element: 'cf-turnstile'")
378 387 await asyncio.sleep(3)
Modified g4f/Provider/CopilotSession.py +1 -1
@@ -62,7 +62,7 @@ class CopilotSession(AsyncAuthedProvider, ProviderModelMixin):
62 62 lock = asyncio.Lock()
63 63
64 64 @classmethod
65 async def on_auth_async(cls, cookies: dict = None, proxy: str = None, **kwargs) -> AsyncIterator:
65 async def on_auth_async(cls, *args, **kwargs) -> AsyncIterator:
66 66 yield AuthResult()
67 67
68 68 @classmethod
Modified g4f/Provider/needs_auth/Antigravity.py +6 -7
@@ -1121,14 +1121,13 @@ class AntigravityProvider:
1121 1121 },
1122 1122 }
1123 1123
1124 # Add tool config if specified
1124 # Add tool config if specified, only include allowedFunctionNames if mode is ANY
1125 1125 if tool_choice and gemini_tools:
1126 req_body["request"]["toolConfig"] = {
1127 "functionCallingConfig": {
1128 "mode": tool_choice.upper(),
1129 "allowedFunctionNames": [fd["name"] for fd in function_declarations]
1130 }
1131 }
1126 mode = tool_choice.upper()
1127 function_calling_config = {"mode": mode}
1128 if mode == "ANY":
1129 function_calling_config["allowedFunctionNames"] = [fd["name"] for fd in function_declarations]
1130 req_body["request"]["toolConfig"] = {"functionCallingConfig": function_calling_config}
1132 1131
1133 1132 # Remove None values recursively
1134 1133 def clean_none(d):
Modified g4f/Provider/needs_auth/GeminiCLI.py +10 -6
@@ -680,6 +680,15 @@ class GeminiCLIProvider():
680 680 gemini_tools = [{"functionDeclarations": function_declarations}]
681 681
682 682 # Compose request body
683 # Build toolConfig with allowedFunctionNames only if mode is ANY
684 tool_config = None
685 if tool_choice and gemini_tools:
686 mode = tool_choice.upper()
687 function_calling_config = {"mode": mode}
688 if mode == "ANY":
689 function_calling_config["allowedFunctionNames"] = [fd["name"] for fd in function_declarations]
690 tool_config = {"functionCallingConfig": function_calling_config}
691
683 692 req_body = {
684 693 "model": model,
685 694 "project": project_id,
@@ -700,12 +709,7 @@ class GeminiCLIProvider():
700 709 } if thinking_budget else None,
701 710 },
702 711 "tools": gemini_tools,
703 "toolConfig": {
704 "functionCallingConfig": {
705 "mode": tool_choice.upper(),
706 "allowedFunctionNames": [fd["name"] for fd in function_declarations]
707 }
708 } if tool_choice and gemini_tools else None,
712 "toolConfig": tool_config,
709 713 **requestData
710 714 },
711 715 }