返回提交历史
Modified
g4f/Provider/Cloudflare.py
+8
-7
XFEstudio/gpt4free
refactor: wrap nodriver fallback logic in async function in Cloudflare.py
- Replaced inline `get_args_from_nodriver` logic with a new async function `nodriver_read_models` inside `Cloudflare` class - Added `async def nodriver_read_models()` to handle asynchronous execution of `get_args_from_nodriver` and call `read_models()` - Moved `try/except` block for handling `RuntimeError` and `FileNotFoundError` inside the new async function - Updated fallback assignment `cls.models = cls.fallback_models` and debug logging to be within `nodriver_read_models` exception handler - Replaced `asyncio.run(args)` with `asyncio.run(nodriver_read_models())` to execute the new async function - Modified logic inside `except ResponseStatusError` block in `Cloudflare` class to incorporate the new structure
c9e1bd21
代码差异
1 个文件
+8
-7
@@ -76,14 +76,15 @@ class Cloudflare(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
76
76
read_models()
77
77
except ResponseStatusError as f:
78
78
if has_nodriver:
79
async def nodriver_read_models():
80
try:
81
cls._args = await get_args_from_nodriver(cls.url)
82
read_models()
83
except (RuntimeError, FileNotFoundError) as e:
84
debug.log(f"Nodriver is not available: {type(e).__name__}: {e}")
85
cls.models = cls.fallback_models
79
86
get_running_loop(check_nested=True)
80
try:
81
args = get_args_from_nodriver(cls.url)
82
cls._args = asyncio.run(args)
83
read_models()
84
except (RuntimeError, FileNotFoundError) as e:
85
cls.models = cls.fallback_models
86
debug.log(f"Nodriver is not available: {type(e).__name__}: {e}")
87
asyncio.run(nodriver_read_models())
87
88
else:
88
89
cls.models = cls.fallback_models
89
90
debug.log(f"Nodriver is not installed: {type(f).__name__}: {f}")