summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/base_provider.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-09-20 23:06:52 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-09-20 23:06:52 +0200
commit951a1332a7dc1878feb11b60677faff4bb7b391b (patch)
treefdbd42a844ad9e9eb66244b177f4d13a2254775f /g4f/Provider/base_provider.py
parentImprove code style in async support (diff)
downloadgpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.tar
gpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.tar.gz
gpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.tar.bz2
gpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.tar.lz
gpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.tar.xz
gpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.tar.zst
gpt4free-951a1332a7dc1878feb11b60677faff4bb7b391b.zip
Diffstat (limited to 'g4f/Provider/base_provider.py')
-rw-r--r--g4f/Provider/base_provider.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/g4f/Provider/base_provider.py b/g4f/Provider/base_provider.py
index 003f86ba..0cceb220 100644
--- a/g4f/Provider/base_provider.py
+++ b/g4f/Provider/base_provider.py
@@ -6,7 +6,7 @@ from abc import ABC, abstractmethod
import browser_cookie3
-from ..typing import Any, AsyncGenerator, CreateResult, Union
+from ..typing import Any, AsyncGenerator, CreateResult
class BaseProvider(ABC):
@@ -22,7 +22,9 @@ class BaseProvider(ABC):
def create_completion(
model: str,
messages: list[dict[str, str]],
- stream: bool, **kwargs: Any) -> CreateResult:
+ stream: bool,
+ **kwargs
+ ) -> CreateResult:
raise NotImplementedError()
@@ -118,16 +120,15 @@ class AsyncGeneratorProvider(AsyncProvider):
raise NotImplementedError()
+# Don't create a new event loop in a running async loop.
+# Force use selector event loop on windows and linux use it anyway.
def create_event_loop() -> SelectorEventLoop:
- # Don't create a new loop in a running loop
try:
- if asyncio.get_running_loop() is not None:
- raise RuntimeError(
- 'Use "create_async" instead of "create" function in a async loop.')
- except:
- pass
- # Force use selector event loop on windows and linux use it anyway
- return SelectorEventLoop()
+ asyncio.get_running_loop()
+ except RuntimeError:
+ return SelectorEventLoop()
+ raise RuntimeError(
+ 'Use "create_async" instead of "create" function in a async loop.')
_cookies = {}