返回提交历史
Modified
etc/unittest/asyncio.py
+2
-2
Modified
etc/unittest/integration.py
+9
-0
Modified
g4f/errors.py
+3
-3
Modified
g4f/providers/base_provider.py
+2
-2
XFEstudio/gpt4free
Fix unittests
a4ca5773
代码差异
4 个文件
+16
-7
@@ -19,8 +19,8 @@ class TestChatCompletion(unittest.TestCase):
19
19
return ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, AsyncProviderMock)
20
20
21
21
def test_exception(self):
22
if hasattr(asyncio, '_nest_patched'):
23
self.skipTest('asyncio is already patched')
22
if has_nest_asyncio:
23
self.skipTest('has nest_asyncio')
24
24
self.assertRaises(g4f.errors.NestAsyncioError, asyncio.run, self.run_exception())
25
25
26
26
def test_create(self):
@@ -1,6 +1,12 @@
1
1
import unittest
2
2
import json
3
3
4
try:
5
import nest_asyncio
6
has_nest_asyncio = True
7
except:
8
has_nest_asyncio = False
9
4
10
from g4f.client import Client, ChatCompletion
5
11
from g4f.Provider import Bing, OpenaiChat
6
12
@@ -8,6 +14,9 @@ DEFAULT_MESSAGES = [{"role": "system", "content": 'Response in json, Example: {"
8
14
{"role": "user", "content": "Say success true in json"}]
9
15
10
16
class TestProviderIntegration(unittest.TestCase):
17
def setUp(self):
18
if not has_nest_asyncio:
19
self.skipTest("nest_asyncio is not installed")
11
20
12
21
def test_bing(self):
13
22
client = Client(provider=Bing)
@@ -22,15 +22,15 @@ class RetryNoProviderError(Exception):
22
22
class VersionNotFoundError(Exception):
23
23
...
24
24
25
class NestAsyncioError(Exception):
26
...
27
28
25
class ModelNotSupportedError(Exception):
29
26
...
30
27
31
28
class MissingRequirementsError(Exception):
32
29
...
33
30
31
class NestAsyncioError(MissingRequirementsError):
32
...
33
34
34
class MissingAuthError(Exception):
35
35
...
36
36
@@ -9,7 +9,7 @@ from inspect import signature, Parameter
9
9
from typing import Callable, Union
10
10
from ..typing import CreateResult, AsyncResult, Messages
11
11
from .types import BaseProvider, FinishReason
12
from ..errors import NestAsyncioError, ModelNotSupportedError, MissingRequirementsError
12
from ..errors import NestAsyncioError, ModelNotSupportedError
13
13
from .. import debug
14
14
15
15
if sys.version_info < (3, 10):
@@ -30,7 +30,7 @@ def get_running_loop(check_nested: bool) -> Union[AbstractEventLoop, None]:
30
30
import nest_asyncio
31
31
nest_asyncio.apply(loop)
32
32
except ImportError:
33
raise MissingRequirementsError('Install "nest_asyncio" package')
33
raise NestAsyncioError('Install "nest_asyncio" package')
34
34
return loop
35
35
except RuntimeError:
36
36
pass