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

XFEstudio/gpt4free

feat(deepinfra): enhance Turnstile integration with BrowserConfig and add quota method

1b247ac1
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +19 -7
Modified g4f/Provider/deepinfra/__init__.py +15 -6
@@ -5,6 +5,7 @@ import requests
5 5 import time
6 6
7 7 from ..template import OpenaiTemplate
8 from ...requests import BrowserConfig
8 9 from .turnstile import Turnstile
9 10
10 11 def find_free_port() -> int:
@@ -17,12 +18,16 @@ def get_turnstile_token_sync(model: str) -> str:
17 18 """Get Turnstile token using Turnstile with a fallback to DrissionPage."""
18 19 # 1. Try our lightweight CDP client first
19 20 try:
20 import os
21 import tempfile
22 port = find_free_port()
23 # Use a persistent temp directory to preserve browser session cookies and Turnstile reputation
24 user_data_dir = os.path.join(tempfile.gettempdir(), "g4f_chrome_profile_light")
25 client = Turnstile(port=port, user_data_dir=user_data_dir)
21 if not BrowserConfig.port:
22 import os
23 import tempfile
24 port = find_free_port()
25 # Use a persistent temp directory to preserve browser session cookies and Turnstile reputation
26 user_data_dir = os.path.join(tempfile.gettempdir(), "g4f_chrome_profile_light")
27 client = Turnstile(port=port, user_data_dir=user_data_dir)
28 else:
29 client = Turnstile(port=BrowserConfig.port)
30 client.connect() # Ensure connection if using a specified port
26 31 try:
27 32 token = client.get_token(model)
28 33 if token:
@@ -93,6 +98,10 @@ class DeepInfra(OpenaiTemplate):
93 98
94 99 default_model = "zai-org/GLM-5.2"
95 100
101 @classmethod
102 async def get_quota(cls, **kwargs):
103 return {}
104
96 105 @classmethod
97 106 def get_models(cls, **kwargs):
98 107 if not cls.models:
Modified g4f/Provider/deepinfra/turnstile.py +4 -1
@@ -96,7 +96,10 @@ class Turnstile:
96 96 ]
97 97
98 98 self.process = subprocess.Popen(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
99
99
100 self.connect() # Wait for Chrome to be ready and connect via WebSocket
101
102 def connect(self):
100 103 # Wait for CDP port readiness and retrieve the WebSocket URL
101 104 ws_url = None
102 105 for i in range(40): # Up to 20 seconds