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

XFEstudio/gpt4free

Use default lazy loading

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

代码差异

2 个文件 +390 -138
Modified g4f/Provider/deepinfra/__init__.py +8 -4
@@ -17,6 +17,7 @@ def find_free_port() -> int:
17 17 def get_turnstile_token_sync(model: str) -> str:
18 18 """Get Turnstile token using Turnstile with a fallback to DrissionPage."""
19 19 # 1. Try our lightweight CDP client first
20 first_error = None
20 21 try:
21 22 if not BrowserConfig.port:
22 23 import os
@@ -33,10 +34,12 @@ def get_turnstile_token_sync(model: str) -> str:
33 34 if token:
34 35 return token
35 36 print("[DeepInfra] Turnstile failed to obtain token. Trying fallback option (DrissionPage)...")
37 except:
38 raise
36 39 finally:
37 40 client.close()
38 41 except Exception as e:
39 print(f"[DeepInfra] Turnstile error: {e}. Trying fallback option (DrissionPage)...")
42 first_error = e
40 43
41 44 # 2. Fallback option: try original DrissionPage if installed
42 45 try:
@@ -79,9 +82,8 @@ def get_turnstile_token_sync(model: str) -> str:
79 82 page.quit()
80 83 except:
81 84 pass
82 except Exception as e:
83 print(f"[DeepInfra] Fallback DrissionPage method error: {e}")
84
85 except:
86 raise first_error if first_error else Exception("Failed to obtain Turnstile token using both methods.")
85 87 return ""
86 88
87 89 async def get_turnstile_token_async() -> str:
@@ -125,6 +127,8 @@ class DeepInfra(OpenaiTemplate):
125 127 if headers is None:
126 128 headers = {}
127 129 headers["X-DeepInfra-Turnstile"] = token
130 else:
131 raise ValueError("Failed to obtain Turnstile token for DeepInfra request.")
128 132
129 133 async for chunk in super().create_async_generator(model, messages, api_key=api_key, headers=headers, **kwargs):
130 134 yield chunk