返回提交历史
Modified
etc/unittest/__main__.py
+0
-1
Modified
etc/unittest/backend.py
+1
-1
Modified
etc/unittest/integration.py
+18
-15
Modified
etc/unittest/main.py
+0
-12
Modified
g4f/Provider/Copilot.py
+1
-0
XFEstudio/gpt4free
Update unittests
2fe43166
代码差异
5 个文件
+20
-29
@@ -6,6 +6,5 @@ from .main import *
6
6
from .model import *
7
7
from .client import *
8
8
from .include import *
9
from .integration import *
10
9
11
10
unittest.main()
@@ -46,4 +46,4 @@ class TestBackendApi(unittest.TestCase):
46
46
self.skipTest(e)
47
47
except MissingRequirementsError:
48
48
self.skipTest("search is not installed")
49
self.assertEqual(4, len(result))
49
self.assertTrue(len(result) >= 4)
@@ -1,36 +1,39 @@
1
1
import unittest
2
2
import json
3
3
4
try:
5
import nest_asyncio
6
has_nest_asyncio = True
7
except ImportError:
8
has_nest_asyncio = False
9
10
from g4f.client import Client, ChatCompletion
11
from g4f.Provider import Bing, OpenaiChat
4
from g4f.client import Client, AsyncClient, ChatCompletion
5
from g4f.Provider import Copilot, DDG
12
6
13
7
DEFAULT_MESSAGES = [{"role": "system", "content": 'Response in json, Example: {"success": false}'},
14
8
{"role": "user", "content": "Say success true in json"}]
15
9
16
10
class TestProviderIntegration(unittest.TestCase):
17
def setUp(self):
18
if not has_nest_asyncio:
19
self.skipTest("nest_asyncio is not installed")
20
11
21
12
def test_bing(self):
22
self.skipTest("Not working")
23
client = Client(provider=Bing)
13
client = Client(provider=Copilot)
24
14
response = client.chat.completions.create(DEFAULT_MESSAGES, "", response_format={"type": "json_object"})
25
15
self.assertIsInstance(response, ChatCompletion)
26
16
self.assertIn("success", json.loads(response.choices[0].message.content))
27
17
28
18
def test_openai(self):
29
self.skipTest("not working in this network")
30
client = Client(provider=OpenaiChat)
19
client = Client(provider=DDG)
31
20
response = client.chat.completions.create(DEFAULT_MESSAGES, "", response_format={"type": "json_object"})
32
21
self.assertIsInstance(response, ChatCompletion)
33
22
self.assertIn("success", json.loads(response.choices[0].message.content))
34
23
24
class TestChatCompletionAsync(unittest.IsolatedAsyncioTestCase):
25
26
async def test_bing(self):
27
client = AsyncClient(provider=Copilot)
28
response = await client.chat.completions.create(DEFAULT_MESSAGES, "", response_format={"type": "json_object"})
29
self.assertIsInstance(response, ChatCompletion)
30
self.assertIn("success", json.loads(response.choices[0].message.content))
31
32
async def test_openai(self):
33
client = AsyncClient(provider=DDG)
34
response = await client.chat.completions.create(DEFAULT_MESSAGES, "", response_format={"type": "json_object"})
35
self.assertIsInstance(response, ChatCompletion)
36
self.assertIn("success", json.loads(response.choices[0].message.content))
37
35
38
if __name__ == '__main__':
36
39
unittest.main()
@@ -7,18 +7,6 @@ from .mocks import ProviderMock
7
7
8
8
DEFAULT_MESSAGES = [{'role': 'user', 'content': 'Hello'}]
9
9
10
class NoTestChatCompletion(unittest.TestCase):
11
12
def no_test_create_default(self):
13
result = ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES)
14
if "Good" not in result and "Hi" not in result:
15
self.assertIn("Hello", result)
16
17
def no_test_bing_provider(self):
18
provider = g4f.Provider.Bing
19
result = ChatCompletion.create(g4f.models.default, DEFAULT_MESSAGES, provider)
20
self.assertIn("Bing", result)
21
22
10
class TestGetLastProvider(unittest.TestCase):
23
11
24
12
def test_get_last_provider(self):
@@ -64,6 +64,7 @@ class Copilot(AbstractProvider):
64
64
65
65
websocket_url = cls.websocket_url
66
66
access_token = None
67
headers = None
67
68
cookies = conversation.cookie_jar if conversation is not None else None
68
69
if cls.needs_auth:
69
70
if conversation is None or conversation.access_token is None: