From 567b39c3301776cca9241ecef8913f38c26bb9c5 Mon Sep 17 00:00:00 2001 From: Ryuk <88324835+anonymousx97@users.noreply.github.com> Date: Mon, 20 May 2024 09:53:37 +0530 Subject: Update base_provider: Do not nest patch uvloop loop. --- g4f/providers/base_provider.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'g4f') diff --git a/g4f/providers/base_provider.py b/g4f/providers/base_provider.py index 5624c9e1..d6c24387 100644 --- a/g4f/providers/base_provider.py +++ b/g4f/providers/base_provider.py @@ -30,6 +30,13 @@ if sys.platform == 'win32': def get_running_loop(check_nested: bool) -> Union[AbstractEventLoop, None]: try: loop = asyncio.get_running_loop() + # Do not patch uvloop loop because its incompatible. + try: + import uvloop + if isinstance(loop, uvloop.Loop): + return + except (ImportError, ModuleNotFoundError): + pass if check_nested and not hasattr(loop.__class__, "_nest_patched"): try: import nest_asyncio @@ -290,4 +297,4 @@ class ProviderModelMixin: elif model not in cls.get_models() and cls.models: raise ModelNotSupportedError(f"Model is not supported: {model} in: {cls.__name__}") debug.last_model = model - return model \ No newline at end of file + return model -- cgit v1.2.3